Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/drivers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,26 @@ export function parseconnectionstring(connectionstring: string): SQLiteCloudConf
})

const config: SQLiteCloudConfig = {
...options,
username: decodeURIComponent(url.username),
password: decodeURIComponent(url.password),
password_hashed: options.password_hashed ? parseBoolean(options.password_hashed) : undefined,
host: url.hostname,
// type cast values
port: url.port ? parseInt(url.port) : undefined,
...options
insecure: options.insecure ? parseBoolean(options.insecure) : undefined,
timeout: options.timeout ? parseInt(options.timeout) : undefined,
zerotext: options.zerotext ? parseBoolean(options.zerotext) : undefined,
create: options.create ? parseBoolean(options.create) : undefined,
memory: options.memory ? parseBoolean(options.memory) : undefined,
compression: options.compression ? parseBoolean(options.compression) : undefined,
non_linearizable: options.non_linearizable ? parseBoolean(options.non_linearizable) : undefined,
noblob: options.noblob ? parseBoolean(options.noblob) : undefined,
maxdata: options.maxdata ? parseInt(options.maxdata) : undefined,
maxrows: options.maxrows ? parseInt(options.maxrows) : undefined,
maxrowset: options.maxrowset ? parseInt(options.maxrowset) : undefined,
usewebsocket: options.usewebsocket ? parseBoolean(options.usewebsocket) : undefined,
verbose: options.verbose ? parseBoolean(options.verbose) : undefined
}

// either you use an apikey or username and password
Expand Down
26 changes: 25 additions & 1 deletion test/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('parseconnectionstring', () => {
expect(config4).toEqual({
host: 'host',
apikey: 'yyy',
maxrows: '42' // only parsing here, validation is later in validateConfiguration
maxrows: 42 // only parsing here, validation is later in validateConfiguration
})
})

Expand Down Expand Up @@ -138,6 +138,30 @@ describe('parseconnectionstring', () => {
database: 'database'
})
})

it('should parse connection with insecure as bool or number', () => {
let connectionstring = `sqlitecloud://host:1234/database?insecure=true`
let config = parseconnectionstring(connectionstring)

expect(config.insecure).toBe(true)

connectionstring = `sqlitecloud://host:1234/database?insecure=1`
config = parseconnectionstring(connectionstring)

expect(config.insecure).toBe(true)

connectionstring = `sqlitecloud://host:1234/database?insecure=0`
config = parseconnectionstring(connectionstring)

expect(config.insecure).toBe(false)
})

it('should parse connection with timeout as number', () => {
let connectionstring = `sqlitecloud://host:1234/database?timeout=123`
let config = parseconnectionstring(connectionstring)

expect(config.timeout).toBe(123)
})
})

describe('getTestingDatabaseName', () => {
Expand Down
Loading