Skip to content

Commit 4b26ead

Browse files
author
Daniele Briggi
committed
fix(config): config properties cast
Config values from the connection string are parsed as boolean or number
1 parent 306dc1a commit 4b26ead

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.422",
3+
"version": "1.0.436",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

src/drivers/utilities.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,26 @@ export function parseconnectionstring(connectionstring: string): SQLiteCloudConf
219219
})
220220

221221
const config: SQLiteCloudConfig = {
222+
...options,
222223
username: decodeURIComponent(url.username),
223224
password: decodeURIComponent(url.password),
225+
password_hashed: options.password_hashed ? parseBoolean(options.password_hashed) : undefined,
224226
host: url.hostname,
227+
// type cast values
225228
port: url.port ? parseInt(url.port) : undefined,
226-
...options
229+
insecure: options.insecure ? parseBoolean(options.insecure) : undefined,
230+
timeout: options.timeout ? parseInt(options.timeout) : undefined,
231+
zerotext: options.zerotext ? parseBoolean(options.zerotext) : undefined,
232+
create: options.create ? parseBoolean(options.create) : undefined,
233+
memory: options.memory ? parseBoolean(options.memory) : undefined,
234+
compression: options.compression ? parseBoolean(options.compression) : undefined,
235+
non_linearizable: options.non_linearizable ? parseBoolean(options.non_linearizable) : undefined,
236+
noblob: options.noblob ? parseBoolean(options.noblob) : undefined,
237+
maxdata: options.maxdata ? parseInt(options.maxdata) : undefined,
238+
maxrows: options.maxrows ? parseInt(options.maxrows) : undefined,
239+
maxrowset: options.maxrowset ? parseInt(options.maxrowset) : undefined,
240+
usewebsocket: options.usewebsocket ? parseBoolean(options.usewebsocket) : undefined,
241+
verbose: options.verbose ? parseBoolean(options.verbose) : undefined
227242
}
228243

229244
// either you use an apikey or username and password

test/utilities.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ describe('parseconnectionstring', () => {
138138
database: 'database'
139139
})
140140
})
141+
142+
it('should parse connection with insecure as bool or number', () => {
143+
let connectionstring = `sqlitecloud://host:1234/database?insecure=true`
144+
let config = parseconnectionstring(connectionstring)
145+
146+
expect(config.insecure).toBe(true)
147+
148+
connectionstring = `sqlitecloud://host:1234/database?insecure=1`
149+
config = parseconnectionstring(connectionstring)
150+
151+
expect(config.insecure).toBe(true)
152+
153+
connectionstring = `sqlitecloud://host:1234/database?insecure=0`
154+
config = parseconnectionstring(connectionstring)
155+
156+
expect(config.insecure).toBe(false)
157+
})
158+
159+
it('should parse connection with timeout as number', () => {
160+
let connectionstring = `sqlitecloud://host:1234/database?timeout=123`
161+
let config = parseconnectionstring(connectionstring)
162+
163+
expect(config.timeout).toBe(123)
164+
})
141165
})
142166

143167
describe('getTestingDatabaseName', () => {

0 commit comments

Comments
 (0)