From d5eb13d5a71e1282aa1d4973e04e63ae3abae277 Mon Sep 17 00:00:00 2001 From: Marvin Luchs Date: Tue, 4 Nov 2025 09:54:50 +0100 Subject: [PATCH] Add support for named in-memory databases using the ?mode=memory connection query param --- packages/libsql-core/src/config.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/libsql-core/src/config.ts b/packages/libsql-core/src/config.ts index 72cc4beb..e1d89ec7 100644 --- a/packages/libsql-core/src/config.ts +++ b/packages/libsql-core/src/config.ts @@ -33,7 +33,9 @@ const inMemoryMode = ":memory:"; export function isInMemoryConfig(config: ExpandedConfig): boolean { return ( config.scheme === "file" && - (config.path === ":memory:" || config.path.startsWith(":memory:?")) + (config.path === ":memory:" || + config.path.startsWith(":memory:?") || + config.path.split("?")[1]?.includes("mode=memory")) ); } @@ -66,7 +68,10 @@ export function expandConfig( const originalUriScheme = uri.scheme.toLowerCase(); const isInMemoryMode = originalUriScheme === "file" && - uri.path === inMemoryMode && + (uri.path === inMemoryMode || + uri.query?.pairs.find( + ({ key, value }) => key === "mode" && value === "memory", + )) && uri.authority === undefined; let queryParamsDef: queryParamsDef; @@ -77,6 +82,11 @@ export function expandConfig( update: (key, value) => connectionQueryParams.push(`${key}=${value}`), }, + mode: { + values: ["memory"], + update: (key, value) => + connectionQueryParams.push(`${key}=${value}`), + }, }; } else { queryParamsDef = { @@ -150,8 +160,8 @@ export function expandConfig( ) { throw new LibsqlError( 'The client supports only "libsql:", "wss:", "ws:", "https:", "http:" and "file:" URLs, ' + - `got ${JSON.stringify(uri.scheme + ":")}. ` + - `For more information, please read ${supportedUrlLink}`, + `got ${JSON.stringify(uri.scheme + ":")}. ` + + `For more information, please read ${supportedUrlLink}`, "URL_SCHEME_NOT_SUPPORTED", ); }