Docs
backend/databases

SQL

Storecraft supports all dialects of SQL:

  • SQLite
  • Postgres
  • MySQL

through the @storecraft/database-sql-base package.

We are working on adding integrations on top of that library to support SQL cloud databases providers such as:

  • turso
  • Cloudflare D1
  • Neon
  • Vercel Postgres

The package is built on top of the fantastic Kysely query builder library. Which means you can create your own adapter for your favourite cloud provider or service to create a serverless or serverful friendly integration.

All of the transactions are non-interactive, which will help to integrate well with cloud databases

SQLITE

Here is a sample of local sqlite integration

npm i @storecraft/core @storecraft/database-sql-base better-sqlite3
import { App } from '@storecraft/core';
import { SQL } from '@storecraft/database-sql-base';
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
import { NodePlatform } from '@storecraft/core/platform/node';
import SQLite from 'better-sqlite3'
import { SqliteDialect } from 'kysely';
export const sqlite_dialect = new SqliteDialect(
{
database: async () => new SQLite(join(homedir(), 'db.sqlite')),
}
);
const app = new App(
{
auth_admins_emails: ['[email protected]'],
auth_secret_access_token: 'auth_secret_access_token',
auth_secret_refresh_token: 'auth_secret_refresh_token'
}
)
.withPlatform(new NodePlatform())
.withDatabase(
new SQL({
dialect: sqlite_dialect,
dialect_type: 'SQLITE'
})
)
.init();
await migrateToLatest(app.__show_me_everything.db, false);

POSTGRES

Here is a sample of local postgres integration

npm i @storecraft/core @storecraft/database-sql-base pg
import { App } from '@storecraft/core';
import { SQL } from '@storecraft/database-sql-base';
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
import { NodePlatform } from '@storecraft/core/platform/node';
import { PostgresDialect } from 'kysely';
import pg from 'pg'
const pg_dialect = new PostgresDialect(
{
pool: new pg.Pool(
{
host: process.env.POSTGRES_HOST,
port: parseInt(process.env.POSTGRES_PORT),
user: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
}
)
}
);
const app = new App(
{
auth_admins_emails: ['[email protected]'],
auth_secret_access_token: 'auth_secret_access_token',
auth_secret_refresh_token: 'auth_secret_refresh_token'
}
)
.withPlatform(new NodePlatform())
.withDatabase(
new SQL({
dialect: pg_dialect,
dialect_type: 'POSTGRES'
})
).init();
await migrateToLatest(app.__show_me_everything.db, false);

MYSQL

Here is a sample of local mysql integration

npm i @storecraft/core @storecraft/database-sql-base mysql2
import { App } from '@storecraft/core';
import { SQL } from '@storecraft/database-sql-base';
import { migrateToLatest } from '@storecraft/database-sql-base/migrate.js';
import { NodePlatform } from '@storecraft/core/platform/node';
import { MysqlDialect } from 'kysely';
import { createPool } from 'mysql2'
export const dialect = new MysqlDialect({
pool: createPool({
database: process.env.MYSQL_DB_NAME,
host: process.env.MYSQL_HOST,
port: parseInt(process.env.MYSQL_PORT),
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
})
});
const app = new App(
{
auth_admins_emails: ['[email protected]'],
auth_secret_access_token: 'auth_secret_access_token',
auth_secret_refresh_token: 'auth_secret_refresh_token'
}
)
.withPlatform(new NodePlatform())
.withDatabase(
new SQL({
dialect: dialect,
dialect_type: 'MYSQL'
})
).init();
await migrateToLatest(app.__show_me_everything.db, false);

All Rights Reserved, storecraft, (2025)