Registry / database / kysely-dialect-tauri

kysely-dialect-tauri

JSON →
library1.2.1jsnpmunverified

A Kysely dialect for Tauri apps using the official @tauri-apps/plugin-sql to connect to databases. Current stable version is 1.2.1. It is developed as part of the kysely-sqlite-tools monorepo. Currently only supports SQLite. The dialect leverages Tauri's SQL plugin to load databases asynchronously, using a callback pattern that provides the SQLite prefix. It is primarily used with Kysely (>=0.26) and requires @tauri-apps/plugin-sql ^2.0.0. Differentiating from other Kysely dialects, it is specifically designed for Tauri environments with proper async loading and connection lifecycle management.

npm install kysely-dialect-tauri
INSTALL
IMPORT
SIG · KYSELY-DIALECT-TAU
K
kysely-dialect-tauri
databasejavascriptv1.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TauriSqliteDialect
import { TauriSqliteDialect } from 'kysely-dialect-tauri'
const TauriSqliteDialect = require('kysely-dialect-tauri').TauriSqliteDialect
ESM-only package; named export. CommonJS require with destructuring works, but direct require('kysely-dialect-tauri') fails because default export is undefined.
TauriSqliteDialectConfig
import type { TauriSqliteDialectConfig } from 'kysely-dialect-tauri'
import { TauriSqliteDialectConfig } from 'kysely-dialect-tauri'
This is a TypeScript type only, not a runtime value. Use `import type` to avoid emitting code.
TauriSqlDB
import type { TauriSqlDB } from 'kysely-dialect-tauri' or omit if not needed
TauriSqlDB is an alias for the Database type from @tauri-apps/plugin-sql. Import it only if you need to type the dialect config 'database' parameter explicitly.

Creates a Kysely instance configured with the Tauri SQLite dialect, using @tauri-apps/plugin-sql to load a database file from the app data directory.

import { appDataDir } from '@tauri-apps/api/path'; import Database from '@tauri-apps/plugin-sql'; import { Kysely } from 'kysely'; import { TauriSqliteDialect } from 'kysely-dialect-tauri'; interface Database { user: { id: number; name: string; }; } async function main() { const db = new Kysely<Database>({ dialect: new TauriSqliteDialect({ database: async (prefix: 'sqlite:') => Database.load(`${prefix}${await appDataDir()}test.db`), }), }); const users = await db.selectFrom('user').selectAll().execute(); console.log(users); } main().catch(console.error);
Debug
Known issues
breakingOnly SQLite is currently supported; PostgreSQL and MySQL are not available despite being mentioned in keywords.
fix
Use for SQLite only. Do not attempt to connect to PostgreSQL or MySQL databases with this dialect.
affects: all versions
gotchaThe `database` config option can be either a direct TauriSqlDB instance or a function that receives the prefix 'sqlite:' and returns a promise. The prefix argument is always 'sqlite:'.
fix
When using the function form, remember that the prefix is 'sqlite:' (string). Example: async (prefix) => Database.load(`${prefix}${await appDataDir()}test.db`)
affects: >=1.0.0
deprecatedThe `onCreateConnection` callback is a Kysely-specific feature and may not be widely used; ensure it is a function that returns void or a promise.
fix
If you don't need custom connection initialization, omit the option.
affects: >=1.0.0
gotchaThe `Database.load` method from @tauri-apps/plugin-sql requires the Tauri runtime and will fail if used outside a Tauri webview.
fix
Only use this dialect inside a Tauri application. For testing, consider mocking the plugin.
affects: all versions
breakingRequires @tauri-apps/plugin-sql version 2.x and Kysely >=0.26. Incompatible with older versions.
fix
Ensure your project has @tauri-apps/plugin-sql@^2.0.0 and kysely@>=0.26 installed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'kysely-dialect-tauri'
Package not installed or import path incorrect (e.g., trying to import a subpath).
fix
Run `npm install kysely-dialect-tauri` and ensure import is `import { TauriSqliteDialect } from 'kysely-dialect-tauri'`
TypeError: TauriSqliteDialect is not a constructor
Using a default import instead of named import; package only exports named members.
fix
Use `import { TauriSqliteDialect } from 'kysely-dialect-tauri'` instead of `import TauriSqliteDialect from 'kysely-dialect-tauri'`
Error: The 'database' option must be a function or a TauriSqlDB instance
Passing an invalid value (e.g., a string) to the config.
fix
Provide either a Database instance from @tauri-apps/plugin-sql or a function that returns one. Example: `database: async (prefix) => Database.load(...)`
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
@tauri-apps/plugin-sqlrequiredRuntime peer dependency required for database operations
kyselyrequiredPeer dependency; Kysely >=0.26 is required for the dialect interface
Agent activity
8 hits · last 30 days
node
8
Resources