Skip to content

Commit a50071e

Browse files
connection url parameters should be case insensitive #67
1 parent d40ce98 commit a50071e

File tree

8 files changed

+100
-7
lines changed

8 files changed

+100
-7
lines changed

.husky/pre-commit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bun install
2+
bun install --production
3+
bun .husky/pre-commit.js
4+
git add package.json
5+
git add bun.lockb

.husky/pre-commit.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// pre-commit.js - update version in package.json with day of the year before checkin
3+
//
4+
5+
const fs = require('fs')
6+
const path = require('path')
7+
8+
const packagePath = path.join(__dirname, '../package.json')
9+
const package = require(packagePath)
10+
11+
const yearStart = new Date('2024-01-01').getTime()
12+
const now = new Date().getTime()
13+
const dayOfYear = Math.floor((now - yearStart) / (1000 * 60 * 60 * 24))
14+
15+
package.version = package.version.replace(/\.\d+$/, `.${dayOfYear}`)
16+
fs.writeFileSync(packagePath, JSON.stringify(package, null, 2))

bun.lockb

271 KB
Binary file not shown.

package-lock.json

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.82",
3+
"version": "1.0.103",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",
@@ -14,15 +14,16 @@
1414
"prettier": "prettier --write 'src/**/*'",
1515
"lint": "eslint ./src/ --fix && tsc --noEmit",
1616
"typedoc": "rm -rf ./docs/ && typedoc --out docs && typedoc --plugin typedoc-plugin-markdown --out docs/markdown",
17-
"npmgui": "npx npm-gui@latest"
17+
"npmgui": "npx npm-gui@latest",
18+
"prepare": "husky"
1819
},
1920
"repository": {
2021
"type": "git",
2122
"url": "git+https://github.com/sqlitecloud/sqlitecloud-js.git"
2223
},
2324
"license": "MIT",
2425
"author": {
25-
"name": "SQLiteCloud, Inc.",
26+
"name": "SQLite Cloud, Inc.",
2627
"email": "support@sqlitecloud.io",
2728
"url": "https://sqlitecloud.io/"
2829
},
@@ -86,4 +87,4 @@
8687
"arrowParens": "avoid",
8788
"printWidth": 160
8889
}
89-
}
90+
}

src/drivers/utilities.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,29 @@ export function parseConnectionString(connectionString: string): SQLiteCloudConf
259259
const url = new URL(knownProtocolUrl)
260260
const options: { [key: string]: string } = {}
261261

262+
// properties that are mixed case in the connection string should be accepted even if the
263+
// customer mistakenly write them in camelCase or kebab-case or whateverTheCase
264+
const mixedCaseProperties = [
265+
'connectionString',
266+
'passwordHashed',
267+
'apiKey',
268+
'createDatabase',
269+
'dbMemory',
270+
'compression',
271+
'noBlob',
272+
'maxData',
273+
'maxRows',
274+
'maxRowset',
275+
'tlsOptions',
276+
'useWebsocket',
277+
'gatewayUrl',
278+
'clientId'
279+
]
280+
262281
url.searchParams.forEach((value, key) => {
263-
options[key] = value
282+
let normalizedKey = key.toLowerCase().replaceAll('-', '').replaceAll('_', '')
283+
const mixedCaseKey = mixedCaseProperties.find(mixedCaseProperty => mixedCaseProperty.toLowerCase() == normalizedKey)
284+
options[mixedCaseKey || normalizedKey] = value
264285
})
265286

266287
const config: SQLiteCloudConfig = {

test/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SQLiteCloudTlsConnection } from '../src/drivers/connection-tls'
1212
import { SQLiteCloudWebsocketConnection } from '../src/drivers/connection-ws'
1313

1414
import { SQLiteCloudConnection, SQLiteCloudRowset } from '../src'
15+
import { expect } from '@jest/globals'
1516
import * as dotenv from 'dotenv'
1617
dotenv.config()
1718

test/utilities.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { SQLiteCloudError } from '../src/index'
66
import { prepareSql, parseConnectionString } from '../src/drivers/utilities'
77
import { getTestingDatabaseName } from './shared'
88

9+
import { expect, describe, it } from '@jest/globals'
10+
911
describe('prepareSql', () => {
1012
it('should replace single ? parameter', () => {
1113
const sql = prepareSql('SELECT * FROM users WHERE name = ?', 'John')
@@ -115,6 +117,38 @@ describe('parseConnectionString', () => {
115117
})
116118
})
117119

120+
it('should parse options regardless of case', () => {
121+
const connectionString1 = 'sqlitecloud://host?apiKey=xxx'
122+
const config1 = parseConnectionString(connectionString1)
123+
expect(config1).toEqual({
124+
host: 'host',
125+
apiKey: 'xxx'
126+
})
127+
128+
const connectionString2 = 'sqlitecloud://host?apikey=yyy'
129+
const config2 = parseConnectionString(connectionString2)
130+
expect(config2).toEqual({
131+
host: 'host',
132+
apiKey: 'yyy'
133+
})
134+
135+
const connectionString3 = 'sqlitecloud://host?api_key=yyy&no_blob=true'
136+
const config3 = parseConnectionString(connectionString3)
137+
expect(config3).toEqual({
138+
host: 'host',
139+
apiKey: 'yyy',
140+
noBlob: 'true' // only parsing here, validation is later in validateConfiguration
141+
})
142+
143+
const connectionString4 = 'sqlitecloud://host?api-key=yyy&max-rows=42'
144+
const config4 = parseConnectionString(connectionString4)
145+
expect(config4).toEqual({
146+
host: 'host',
147+
apiKey: 'yyy',
148+
maxRows: '42' // only parsing here, validation is later in validateConfiguration
149+
})
150+
})
151+
118152
it('should parse connection string without port', () => {
119153
const connectionString = 'sqlitecloud://user:password@host'
120154
const config = parseConnectionString(connectionString)

0 commit comments

Comments
 (0)