-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Panic after enabling embedded replica when using named placeholders #232
Comments
Note: embedded replica isn't possible due to bug tursodatabase/libsql-client-ts#232
I was able to narrow this issue down. It seems to occur when I use named placeholders. This works: const result = await client.execute({
sql: "SELECT * FROM users WHERE id = ?",
args: [1],
}); This panics: const result = await client.execute({
sql: "SELECT * FROM users WHERE id = $id",
args: {id: 23},
}); I've tried |
I just learned about the same problem here. Also narrowed down to this issue. As I rely heavily in named arguments, I've created a helper to transform from named to positional arguments. Hope it helps anyone who comes to this issue while it's not fixed: function convertToPositionalParams({sql, args}) {
const paramNames = Object.keys(params);
const positionalParams = [];
const paramMap = {};
// Replace named parameters in the SQL with positional parameters (?)
const transformedSql = sql.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g, (_, paramName) => {
if (paramNames.includes(paramName)) {
if (!(paramName in paramMap)) {
positionalParams.push(params[paramName]);
paramMap[paramName] = positionalParams.length; // Track the index of each parameter
}
return '?';
} else {
throw new Error(`Parameter ${paramName} not found in params object`);
}
});
return {
sql: transformedSql,
args: positionalParams
};
} In this case, it's using |
Everything works fine when the client has no
syncUrl
and usesEVENT_DB_SYNC_URL
for theurl
.Using @libsql/client 0.7
The text was updated successfully, but these errors were encountered: