@@ -61,12 +61,14 @@ export function getInitializationCommands(config: SQLiteCloudConfig): string {
6161 let commands = 'SET CLIENT KEY NONLINEARIZABLE TO 1;'
6262
6363 // first user authentication, then all other commands
64- if ( config . apikey ) {
65- commands += `AUTH APIKEY ${ config . apikey } ;`
66- } else if ( config . token ) {
67- commands += `AUTH TOKEN ${ config . token } ;`
68- } else {
69- commands += `AUTH USER ${ config . username || '' } ${ config . password_hashed ? 'HASH' : 'PASSWORD' } ${ config . password || '' } ;`
64+ if ( ! config . unauthenticated ) {
65+ if ( config . apikey ) {
66+ commands += `AUTH APIKEY ${ config . apikey } ;`
67+ } else if ( config . token ) {
68+ commands += `AUTH TOKEN ${ config . token } ;`
69+ } else {
70+ commands += `AUTH USER ${ config . username || '' } ${ config . password_hashed ? 'HASH' : 'PASSWORD' } ${ config . password || '' } ;`
71+ }
7072 }
7173
7274 if ( config . compression ) {
@@ -94,7 +96,7 @@ export function getInitializationCommands(config: SQLiteCloudConfig): string {
9496 commands += 'SET CLIENT KEY NONLINEARIZABLE TO 0;'
9597 }
9698
97- if ( config . database ) {
99+ if ( ! config . unauthenticated && config . database ) {
98100 if ( config . create && ! config . memory ) {
99101 commands += `CREATE DATABASE ${ config . database } IF NOT EXISTS;`
100102 }
@@ -198,14 +200,15 @@ export function validateConfiguration(config: SQLiteCloudConfig): SQLiteCloudCon
198200 config . create = parseBoolean ( config . create )
199201 config . non_linearizable = parseBoolean ( config . non_linearizable )
200202 config . insecure = parseBoolean ( config . insecure )
203+ config . unauthenticated = parseBoolean ( config . unauthenticated )
201204
202205 const hasCredentials = ( config . username && config . password ) || config . apikey || config . token
203- if ( ! config . host || ! hasCredentials ) {
206+ if ( ! config . host || ( ! config . unauthenticated && ! hasCredentials ) ) {
204207 console . error ( 'SQLiteCloudConnection.validateConfiguration - missing arguments' , config )
205208 throw new SQLiteCloudError ( 'The user, password and host arguments, the ?apikey= or the ?token= must be specified.' , { errorCode : 'ERR_MISSING_ARGS' } )
206209 }
207210
208- if ( ! config . connectionstring ) {
211+ if ( ! config . connectionstring && ! config . unauthenticated ) {
209212 // build connection string from configuration, values are already validated
210213 config . connectionstring = `sqlitecloud://${ config . host } :${ config . port } /${ config . database || '' } `
211214 if ( config . apikey ) {
@@ -258,6 +261,7 @@ export function parseconnectionstring(connectionstring: string): SQLiteCloudConf
258261 memory : options . memory ? parseBoolean ( options . memory ) : undefined ,
259262 compression : options . compression ? parseBoolean ( options . compression ) : undefined ,
260263 non_linearizable : options . non_linearizable ? parseBoolean ( options . non_linearizable ) : undefined ,
264+ unauthenticated : options . unauthenticated ? parseBoolean ( options . unauthenticated ) : undefined ,
261265 noblob : options . noblob ? parseBoolean ( options . noblob ) : undefined ,
262266 maxdata : options . maxdata ? parseInt ( options . maxdata ) : undefined ,
263267 maxrows : options . maxrows ? parseInt ( options . maxrows ) : undefined ,
0 commit comments