https://github.com/kysely-org/kysely-singlestore
Kysely dialects, plugins and other goodies for Singlestore (formerly MemSQL)
https://github.com/kysely-org/kysely-singlestore
analytics browser columnstore data-api deno dialect in-memory-database kysely mysql query-builder serverless singlestore sql type-safe typescript
Last synced: 4 months ago
JSON representation
Kysely dialects, plugins and other goodies for Singlestore (formerly MemSQL)
- Host: GitHub
- URL: https://github.com/kysely-org/kysely-singlestore
- Owner: kysely-org
- License: mit
- Created: 2022-09-23T20:51:17.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-12T20:26:43.000Z (almost 2 years ago)
- Last Synced: 2025-08-10T14:26:00.218Z (11 months ago)
- Topics: analytics, browser, columnstore, data-api, deno, dialect, in-memory-database, kysely, mysql, query-builder, serverless, singlestore, sql, type-safe, typescript
- Language: TypeScript
- Homepage:
- Size: 412 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README

# kysely-singlestore
[](https://www.codacy.com/gh/igalklebanov/kysely-singlestore/dashboard?utm_source=github.com&utm_medium=referral&utm_content=igalklebanov/kysely-singlestore&utm_campaign=Badge_Grade)

[Kysely](https://github.com/koskimas/kysely) dialects, plugins and other goodies for [SingleStore](https://www.singlestore.com/) (formerly MemSQL).
## Installation
### Node.js
#### NPM 7+
```bash
npm i kysely-singlestore
```
#### NPM <7
```bash
npm i kysely-singlestore kysely
```
#### Yarn
```bash
yarn add kysely-singlestore kysely
```
#### PNPM
```bash
pnpm add kysely-singlestore kysely
```
### Deno
This package uses/extends some [Kysely](https://github.com/koskimas/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`](https://deno.land/manual@v1.26.1/linking_to_external_code/import_maps) file.
```json
{
"imports": {
"kysely": "https://cdn.jsdelivr.net/npm/kysely@0.22.0/dist/esm/index.js"
}
}
```
## Usage
### Data API Dialect
[SingleStore Data API](https://docs.singlestore.com/managed-service/en/reference/data-api.html) allows executing SQL queries in the browser and is a great fit for serverless functions and other auto-scaling compute services. It does not support transactions at this point in time.
#### Node.js 16.8+
Older node versions are supported as well, just swap [`undici`](https://github.com/nodejs/undici) with [`node-fetch`](https://github.com/node-fetch/node-fetch).
```ts
import {Kysely} from 'kysely'
import {SingleStoreDataApiDialect, SingleStoreDataType} from 'kysely-singlestore'
import {fetch} from 'undici'
interface Database {
person: {
id: string
first_name: string | null
last_name: string | null
}
pet: {
id: string
name: string
owner_id: string
}
}
const db = new Kysely({
dialect: new SingleStoreDataApiDialect({
database: '',
deserialization: {
castDatesAsNativeDates: true,
castTinyIntAsBoolean: true,
deserialize: (value, dataType, columnName) =>
dataType === SingleStoreDataType.Json && columnName === 'pet' ? new Pet(value) : undefined,
unwrapDecimals: true,
},
fetch,
hostname: '',
password: '',
username: '',
}),
})
```
#### Browser
```ts
import {Kysely} from 'kysely'
import {SingleStoreDataApiDialect, SingleStoreDataType} from 'kysely-singlestore'
interface Database {
person: {
id: string
first_name: string | null
last_name: string | null
}
pet: {
id: string
name: string
owner_id: string
}
}
const db = new Kysely({
dialect: new SingleStoreDataApiDialect({
database: '',
deserialization: {
castDatesAsNativeDates: true,
castTinyIntAsBoolean: true,
deserialize: (value, dataType, columnName) =>
dataType === SingleStoreDataType.Json && columnName === 'pet' ? new Pet(value) : undefined,
unwrapDecimals: true,
},
fetch: window.fetch.bind(window),
hostname: '',
password: '',
username: '',
}),
})
```
#### Deno
```ts
import {Kysely} from 'https://cdn.jsdelivr.net/npm/kysely@0.22.0/dist/esm/index.js'
import {
SingleStoreDataApiDialect,
SingleStoreDataType,
} from 'https://cdn.jsdelivr.net/npm/kysely-singlestore@latest/dist/esm/index.js'
interface Database {
person: {
id: string
first_name: string | null
last_name: string | null
}
pet: {
id: string
name: string
owner_id: string
}
}
const db = new Kysely({
dialect: new SingleStoreDataApiDialect({
database: '',
deserialization: {
castDatesAsNativeDates: true,
castTinyIntAsBoolean: true,
deserialize: (value, dataType, columnName) =>
dataType === SingleStoreDataType.Json && columnName === 'pet' ? new Pet(value) : undefined,
unwrapDecimals: true,
},
fetch: fetch,
hostname: '',
password: '',
username: '',
}),
})
```
### "Classic" Dialect - SoonTM
SingleStore is wire-compatible with MySQL so you can connect to it using `mysql2` in node environments, and take advantage of connection pools and transactions.
## License
MIT License, see `LICENSE`