[continuing from previous post]
Finally, edit createConnection to this:
const createConnection = (config) => {
const knexConfig = { ...config };
if (knexConfig.client === "libsql") {
knexConfig.client = Client_Libsql;
}
if (knexConfig.client === "sqlite") {
const sqlitePackageName = getSqlitePackageName();
knexConfig.client = clientMap[sqlitePackageName];
}
return knex__default.default(knexConfig);
};
Now you store the patch to your code with pnpm patch-commit 'strapi-db-patch'
Remember to install this libsql package: pnpm i @libsql/sqlite3
Then edit your standard config/database.js with something like this:
const connections = {
// ...
libsql: {
connection: {
filename:
"wss://my-strapi-db.turso.io?authToken=my_turso_auth_token",
},
useNullAsDefault: true,
},
I did not get it to work with the libsql:// or https:// protocols, because the connection timed out or something. So you must use wss://
Update the .env to use the libsql connection DATABASE_CLIENT=libsql
You can now run pnpm develop and see the Turso database be filled up with Strapi tables.
My packages at the time of writing were:
“@libsql/sqlite3”: “^0.3.1”,
“@strapi/strapi”: “4.25.9”,
“better-sqlite3”: “8.6.0”,
“knex”: “^3.1.0”,