Kysely dialects, plugins and other goodies for SurrealDB.
SurrealQL is based on SQL, so why not?
npm i kysely-surrealdb
npm i kysely-surrealdb kysely
yarn add kysely-surrealdb kysely
pnpm add kysely-surrealdb kysely
This package uses/extends some Kysely types and classes, which are imported using it's NPM package name -- not a relative file path or CDN url.
To fix that, add an import_map.json
file.
{
"imports": {
"kysely": "https://cdn.jsdelivr.net/npm/[email protected]/dist/esm/index.js"
}
}
SurrealDB's HTTP endpoints allows executing SurrealQL queries in the browser and is a great fit for serverless functions and other auto-scaling compute services.
Older node versions are supported as well, just swap undici
with node-fetch
.
import {GeneratedAlways, Kysely} from 'kysely'
import {SurrealDatabase, SurrealDbHttpDialect} from 'kysely-surrealdb'
import {fetch} from 'undici'
interface Database {
person: {
id: GeneratedAlways<string>
first_name: string | null
last_name: string | null
age: number
}
pet: {
id: GeneratedAlways<string>
name: string
owner_id: string | null
}
}
const db = new Kysely<SurrealDatabase<Database>>({
dialect: new SurrealDbHttpDialect({
database: '<database>',
fetch,
hostname: '<hostname>',
namespace: '<namespace>',
password: '<password>',
username: '<username>',
}),
})
The awesomeness of Kysely, with some SurrealQL query builders patched in.
import {GeneratedAlways, Kysely} from 'kysely'
import {SurrealDbHttpDialect, SurrealKysely} from 'kysely-surrealdb'
import {fetch} from 'undici'
interface Database {
person: {
id: GeneratedAlways<string>
first_name: string | null
last_name: string | null
age: number
}
pet: {
id: GeneratedAlways<string>
name: string
owner_id: string | null
}
}
const db = new SurrealKysely<Database>({
dialect: new SurrealDbHttpDialect({
database: '<database>',
fetch,
hostname: '<hostname>',
namespace: '<namespace>',
password: '<password>',
username: '<username>',
}),
})
await db
.create('person:100')
.set({
first_name: 'Jennifer',
age: 15,
})
.return('none')
.execute()
MIT License, see LICENSE