Skip to content
Open
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
18 changes: 14 additions & 4 deletions packages/libsql-core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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 = {
Expand Down Expand Up @@ -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",
);
}
Expand Down