Experimental/PoC support for libsql in Directus.
Caution
This is an experimental project and consists in workarounds and small patches to make it work without modifying the core of Directus. In order to make Directus work nicely with libsql, some changes need to land in both Directus and libsql first.
Note that the published image is preconfigured to make it easier to test.
docker run --rm -it -p 8055:8055 linefusion/directus-libsql:latest
To run with Turso, set these variables:
DB_SYNC=true
DB_SYNC_URL=libsql://<project>-<org>.turso.io
DB_SYNC_PERIOD=60
DB_AUTH_TOKEN=<your-token>Embedded replica will live inside /directus/database folder.
Run npm init @linefusion/directus-libsql.
Inside the project:
pnpm directusis an alias to Directus CLI with the config file set.pnpm bootstrapis an alias todirectus bootstrapwith the config file set.pnpm startis an alias todirectus startwith the config file set.
Example are given using pnpm, port it to your own package manager of choice.
- Create a Directus project
pnpm create directus-project some-project- Choose SQLite as the database
- Set
./database.sqliteas your database filename - Choose email and password
-
Install these packages in your project:
pnpm install @linefusion/directus-libsqlpnpm install [email protected]
-
Create a
config.jsinside of it:const { withLibsql } = require("@linefusion/directus-libsql"); module.exports = withLibsql();
-
Configure your
.envfile or set these environment variables:DB_FILENAME- where your local sqlite database will live.DB_SYNC- if you want to sync changes (true/false).DB_SYNC_URL- remote url to sync changes to/from (url).DB_SYNC_PERIOD- period to automatically sync changes (in seconds, default 60).DB_AUTH_TOKEN- token for syncing (string).
-
Run Directus with
CONFIG_PATHpointing to the location fo theconfig.jsyou just created.
Check examples folder. Each example has an associated script in the root package.
To run an example use pnpm example:<name> command (it's 'an alias to directus cli).
-
libsqlneeds a fix on the parser in order to behave exactly like SQLite.- See issue here
-
Directus needs to add support for libsql since databases are all hardcoded.
-
Directus could make it easier to use
libsqluntil referenced issue inlibsqlis fixed-
See
columnInfohere-
await this.knex.select('name').from('sqlite_master').whereRaw(`sql LIKE "%AUTOINCREMENT%"`)
to
await this.knex.select('name').from('sqlite_master').whereLike('sql', '%AUTOINCREMENT%')
-
-