Kysely dialects, plugins and other goodies for SurrealDB

Overview

kysely-surrealdb

Powered by TypeScript

Kysely dialects, plugins and other goodies for SurrealDB.

SurrealQL is based on SQL, so why not? :trollface:

Installation

NPM 7+

npm i kysely-surrealdb

NPM <7

npm i kysely-surrealdb kysely

Yarn

yarn add kysely-surrealdb kysely

PNPM

pnpm add kysely-surrealdb kysely

Deno

This package uses/extends some Kysely types and classes, which are imported using its 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"
  }
}

Usage

HTTP Dialect

SurrealDB's HTTP endpoints allow executing SurrealQL queries in the browser and are a great fit for serverless functions and other auto-scaling compute services.

Node.js 16.8+

Older node versions are supported as well, just swap undici with node-fetch.

import {Kysely} from 'kysely'
import {SurrealDatabase, SurrealDbHttpDialect, type SurrealEdge} from 'kysely-surrealdb'
import {fetch} from 'undici'

interface Database {
  person: {
    first_name: string | null
    last_name: string | null
    age: number
  }
  own: SurrealEdge<{
    time: {
      adopted: string
    } | null
  }>
  pet: {
    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>',
  }),
})

Web Socket Dialect - SoonTM

SurrealKysely Query Builder

The awesomeness of Kysely, with some SurrealQL query builders patched in.

import {SurrealDbHttpDialect, SurrealKysely, type SurrealEdge} from 'kysely-surrealdb'
import {fetch} from 'undici'

interface Database {
  person: {
    first_name: string | null
    last_name: string | null
    age: number
  }
  own: SurrealEdge<{
    time: {
      adopted: string
    } | null
  }>
  pet: {
    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()

Supported SurrealQL specific statements:

create, relate.

Why not write a query builder from scratch

Kysely is growing to be THE sql query builder solution in the typescript ecosystem. Koskimas' dedication, attention to detail, experience from creating objection.js, project structure, simplicity, design patterns and philosophy, made adding code to that project a really good experience as a contributor. Taking what's great about that codebase, and patching in SurrealQL stuff seems like an easy win in the short-medium term.

License

MIT License, see LICENSE

You might also like...

Senior Design Project. Water intake tracker. Software for the communication to bottle and app. Software for app and database

WaterMate Senior Design Project. Water intake tracker to provide everyone with an easy to use water tracking system that can be integrated with your f

Nov 10, 2021

Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Oct 11, 2022

Fast and advanced, document based and key-value based NoSQL database that able to work as it is installed.

Fast and advanced, document based and key-value based NoSQL database that able to work as it is installed.

About Fast and advanced, document based and key-value based NoSQL database that able to work as it is installed. Features NoSQL database Can be run as

Dec 7, 2022

Plant trees to harvest apples. Sell apples to buy upgrades. Sell apples and wares to make the most money and top the leaderboard!

Plant trees to harvest apples. Sell apples to buy upgrades. Sell apples and wares to make the most money and top the leaderboard!

Happy Harvesters Apple Orchard Game A browser based game that is also mobile friendly so you can finally say "How about THEM apples". Table of Content

May 21, 2022

XML/HTML parser and processing library for JavaScript and TypeScript

XML/HTML parser and processing library for JavaScript and TypeScript

[VIEW DOCUMENTATION] Robin is an XML parser and processing library that supports a sane version of HTML. It features a set of DOM utilities, including

Oct 5, 2022

Fast and advanced, document-based and key-value-based NoSQL database.

Fast and advanced, document-based and key-value-based NoSQL database.

Contents About Features Installation Links About Fast and advanced, document-based and key-value-based NoSQL database. Features NoSQL database Can be

Dec 7, 2022

Explore, create and deploy your SQLite databases right from your browser. Quick and easy, no installation required.

Explore, create and deploy your SQLite databases right from your browser. Quick and easy, no installation required.

SQLighter (under development, alpha code) SQLighter is a database explorer born for SQLite that helps you design and deploy your application database

Sep 20, 2022

⚡️ lowdb is a small local JSON database powered by Lodash (supports Node, Electron and the browser)

Lowdb Small JSON database for Node, Electron and the browser. Powered by Lodash. ⚡ db.get('posts') .push({ id: 1, title: 'lowdb is awesome'}) .wri

Dec 30, 2022

Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

PostGraphile Instant lightning-fast GraphQL API backed primarily by your PostgreSQL database. Highly customisable and extensible thanks to incredibly

Jan 4, 2023
Comments
  • enhance `SurrealKysely.relate` api.

    enhance `SurrealKysely.relate` api.

    • introduce edge hints (SurrealEdge<E>).
    • limit relate(edge) to just edges.
    • limit from(...) & to(...) to just vertices.
    • multiple specific records from/to overloads.
    enhancement 
    opened by igalklebanov 0
Owner
Igal Klebanov
programming enthusiast, gamer, audiophile. software developer @ Finaloop
Igal Klebanov
WriterAI is an AI based content writing tool that helps users easily write high quality emails, blogs, letters, thesis and other stuff.

WriterAI is an AI based content writing tool that helps users easily write high quality emails, blogs, letters, thesis and other stuff. One can also share their project with others and work as a team.

Ishant Chauhan 67 Jan 2, 2023
A student-made, student-tailored Firefox add-on for Veracross. Provides ease of navigation in Veracross, among with other quality of life features. More features in progress.

Check out the Chrome version! This release is version 1.0.0, so the only feature it has is clickable links to the dropbox from the classpage. Any comm

Webb School CS Club 3 Nov 25, 2022
GraphQL Projects Study Cases with TypeScript/Node.js & Other Stacks

GraphQL Projects Study Cases with TypeScript/Node.js & Other Stacks A real world projects with intention of studying a little bit more about GraphQL w

Glaucia Lemos 15 Dec 5, 2022
Share an abstract-level database over the network or other kind of stream.

many-level Share an abstract-level database over the network or other kind of stream. The successor to multileveldown. If you are upgrading, please se

Level 15 Mar 27, 2022
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

null 30.1k Jan 3, 2023
A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

knex.js A SQL query builder that is flexible, portable, and fun to use! A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle

knex 16.9k Jan 4, 2023
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite datab

MikroORM 5.4k Dec 31, 2022
Azure Data Studio is a data management tool that enables you to work with SQL Server, Azure SQL DB and SQL DW from Windows, macOS and Linux.

Azure Data Studio is a data management tool that enables working with SQL Server, Azure SQL DB and SQL DW from Windows, macOS and Linux.

Microsoft 7k Dec 31, 2022
A Gmail Clone which built with ReactJS and Redux. You can sign in with your Google Account, compose a new e-mail and send realtime emails to the project.

Gmail Clone with ReactJS A Gmail Clone that you can sign in with your Google Account, compose a new e-mail and send realtime emails to the project. Cl

Özge Coşkun Gürsucu 49 Nov 14, 2022