@@ -40,46 +40,47 @@ export function anonimizeError(error: Error): Error {
4040export function getInitializationCommands ( config : SQLiteCloudConfig ) : string {
4141 // we check the credentials using non linearizable so we're quicker
4242 // then we bring back linearizability unless specified otherwise
43- let commands = 'SET CLIENT KEY NONLINEARIZABLE TO 1; '
43+ let commands = 'SET CLIENT KEY NONLINEARIZABLE TO 1;'
4444
45- // TODO: include authentication via token
4645 // first user authentication, then all other commands
4746 if ( config . apikey ) {
48- commands += `AUTH APIKEY ${ config . apikey } ; `
47+ commands += `AUTH APIKEY ${ config . apikey } ;`
48+ } else if ( config . token ) {
49+ commands += `AUTH TOKEN ${ config . token } ;`
4950 } else {
50- commands += `AUTH USER ${ config . username || '' } ${ config . password_hashed ? 'HASH' : 'PASSWORD' } ${ config . password || '' } ; `
51+ commands += `AUTH USER ${ config . username || '' } ${ config . password_hashed ? 'HASH' : 'PASSWORD' } ${ config . password || '' } ;`
5152 }
5253
5354 if ( config . compression ) {
54- commands += 'SET CLIENT KEY COMPRESSION TO 1; '
55+ commands += 'SET CLIENT KEY COMPRESSION TO 1;'
5556 }
5657 if ( config . zerotext ) {
57- commands += 'SET CLIENT KEY ZEROTEXT TO 1; '
58+ commands += 'SET CLIENT KEY ZEROTEXT TO 1;'
5859 }
5960 if ( config . noblob ) {
60- commands += 'SET CLIENT KEY NOBLOB TO 1; '
61+ commands += 'SET CLIENT KEY NOBLOB TO 1;'
6162 }
6263 if ( config . maxdata ) {
63- commands += `SET CLIENT KEY MAXDATA TO ${ config . maxdata } ; `
64+ commands += `SET CLIENT KEY MAXDATA TO ${ config . maxdata } ;`
6465 }
6566 if ( config . maxrows ) {
66- commands += `SET CLIENT KEY MAXROWS TO ${ config . maxrows } ; `
67+ commands += `SET CLIENT KEY MAXROWS TO ${ config . maxrows } ;`
6768 }
6869 if ( config . maxrowset ) {
69- commands += `SET CLIENT KEY MAXROWSET TO ${ config . maxrowset } ; `
70+ commands += `SET CLIENT KEY MAXROWSET TO ${ config . maxrowset } ;`
7071 }
7172
7273 // we ALWAYS set non linearizable to 1 when we start so we can be quicker on login
7374 // but then we need to put it back to its default value if "linearizable" unless set
7475 if ( ! config . non_linearizable ) {
75- commands += 'SET CLIENT KEY NONLINEARIZABLE TO 0; '
76+ commands += 'SET CLIENT KEY NONLINEARIZABLE TO 0;'
7677 }
7778
7879 if ( config . database ) {
7980 if ( config . create && ! config . memory ) {
80- commands += `CREATE DATABASE ${ config . database } IF NOT EXISTS; `
81+ commands += `CREATE DATABASE ${ config . database } IF NOT EXISTS;`
8182 }
82- commands += `USE DATABASE ${ config . database } ; `
83+ commands += `USE DATABASE ${ config . database } ;`
8384 }
8485
8586 return commands
0 commit comments