@bunit/qb 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/dialects/dialects/mysql.d.ts +14 -0
- package/dist/dialects/dialects/postgres.d.ts +14 -0
- package/dist/dialects/dialects/sqlite.d.ts +14 -0
- package/dist/dialects/mysql.mjs +27 -0
- package/dist/dialects/postgres.mjs +27 -0
- package/dist/dialects/sql.d.ts +13 -0
- package/dist/dialects/sqlite.mjs +27 -0
- package/dist/dialects/types.d.ts +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/sql.d.ts +13 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @bunit/qb
|
|
2
|
+
|
|
3
|
+
> Kysely dialects powered by [Bun.SQL](https://bun.net.cn/docs/api/sql) for PostgreSQL, MySQL, and SQLite.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ⚡️ **Native Bun.SQL** - Zero abstraction overhead using Bun's built-in SQL client
|
|
8
|
+
- 🔌 **Kysely Compatible** - Drop-in dialects with full type safety
|
|
9
|
+
- 🎯 **Multi-Database** - PostgreSQL, MySQL, MariaDB, and SQLite support
|
|
10
|
+
- 📦 **Zero Runtime Dependencies** - Only requires Kysely as peer dependency
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
bun add @bunit/qb kysely
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### PostgreSQL
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { Kysely } from "kysely";
|
|
24
|
+
import { PostgresDialect } from "@bunit/qb/dialects/postgres";
|
|
25
|
+
|
|
26
|
+
const db = new Kysely<Database>({
|
|
27
|
+
dialect: new PostgresDialect({
|
|
28
|
+
url: "postgres://user:pass@localhost:5432/mydb",
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### MySQL
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { Kysely } from "kysely";
|
|
37
|
+
import { MySQLDialect } from "@bunit/qb/dialects/mysql";
|
|
38
|
+
|
|
39
|
+
const db = new Kysely<Database>({
|
|
40
|
+
dialect: new MySQLDialect({
|
|
41
|
+
url: "mysql://user:pass@localhost:3306/mydb",
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### SQLite
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Kysely } from "kysely";
|
|
50
|
+
import { SQLiteDialect } from "@bunit/qb/dialects/sqlite";
|
|
51
|
+
|
|
52
|
+
// File-based
|
|
53
|
+
const db = new Kysely<Database>({
|
|
54
|
+
dialect: new SQLiteDialect({
|
|
55
|
+
url: "sqlite://path/to/myapp.db",
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// In-memory
|
|
60
|
+
const memoryDb = new Kysely<Database>({
|
|
61
|
+
dialect: new SQLiteDialect({
|
|
62
|
+
url: ":memory:",
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Advanced Configuration
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { PostgresDialect } from "@bunit/qb/dialects/postgres";
|
|
71
|
+
|
|
72
|
+
const dialect = new PostgresDialect({
|
|
73
|
+
options: {
|
|
74
|
+
hostname: "localhost",
|
|
75
|
+
port: 5432,
|
|
76
|
+
database: "mydb",
|
|
77
|
+
username: "user",
|
|
78
|
+
password: "pass",
|
|
79
|
+
max: 20, // connection pool size
|
|
80
|
+
idleTimeout: 30,
|
|
81
|
+
tls: true,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
[MIT](../../LICENSE) © [Demo Macro](https://www.demomacro.com/)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DatabaseIntrospector, Dialect, DialectAdapter, Driver, QueryCompiler } from "kysely";
|
|
2
|
+
import type { Kysely } from "kysely";
|
|
3
|
+
import type { BunSQLDialectConfig } from "../types";
|
|
4
|
+
export interface MySQLDialectConfig extends BunSQLDialectConfig {
|
|
5
|
+
}
|
|
6
|
+
export declare class MySQLDialect implements Dialect {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(config?: MySQLDialectConfig);
|
|
9
|
+
createDriver(): Driver;
|
|
10
|
+
createQueryCompiler(): QueryCompiler;
|
|
11
|
+
createAdapter(): DialectAdapter;
|
|
12
|
+
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
13
|
+
}
|
|
14
|
+
export default MySQLDialect;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DatabaseIntrospector, Dialect, DialectAdapter, Driver, QueryCompiler } from "kysely";
|
|
2
|
+
import type { Kysely } from "kysely";
|
|
3
|
+
import type { BunSQLDialectConfig } from "../types";
|
|
4
|
+
export interface PostgresDialectConfig extends BunSQLDialectConfig {
|
|
5
|
+
}
|
|
6
|
+
export declare class PostgresDialect implements Dialect {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(config?: PostgresDialectConfig);
|
|
9
|
+
createDriver(): Driver;
|
|
10
|
+
createQueryCompiler(): QueryCompiler;
|
|
11
|
+
createAdapter(): DialectAdapter;
|
|
12
|
+
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
13
|
+
}
|
|
14
|
+
export default PostgresDialect;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DatabaseIntrospector, Dialect, DialectAdapter, Driver, QueryCompiler } from "kysely";
|
|
2
|
+
import type { Kysely } from "kysely";
|
|
3
|
+
import type { BunSQLDialectConfig } from "../types";
|
|
4
|
+
export interface SQLiteDialectConfig extends BunSQLDialectConfig {
|
|
5
|
+
}
|
|
6
|
+
export declare class SQLiteDialect implements Dialect {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(config?: SQLiteDialectConfig);
|
|
9
|
+
createDriver(): Driver;
|
|
10
|
+
createQueryCompiler(): QueryCompiler;
|
|
11
|
+
createAdapter(): DialectAdapter;
|
|
12
|
+
createIntrospector(db: Kysely<any>): DatabaseIntrospector;
|
|
13
|
+
}
|
|
14
|
+
export default SQLiteDialect;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MysqlAdapter } from "kysely";
|
|
2
|
+
import { MysqlIntrospector } from "kysely";
|
|
3
|
+
import { MysqlQueryCompiler } from "kysely";
|
|
4
|
+
import { BunSQLDriver } from "../sql";
|
|
5
|
+
|
|
6
|
+
export class MySQLDialect {
|
|
7
|
+
#config;
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
this.#config = config;
|
|
10
|
+
}
|
|
11
|
+
createDriver() {
|
|
12
|
+
return new BunSQLDriver({
|
|
13
|
+
adapter: "mysql",
|
|
14
|
+
...this.#config
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
createQueryCompiler() {
|
|
18
|
+
return new MysqlQueryCompiler;
|
|
19
|
+
}
|
|
20
|
+
createAdapter() {
|
|
21
|
+
return new MysqlAdapter;
|
|
22
|
+
}
|
|
23
|
+
createIntrospector(db) {
|
|
24
|
+
return new MysqlIntrospector(db);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default MySQLDialect;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PostgresAdapter } from "kysely";
|
|
2
|
+
import { PostgresIntrospector } from "kysely";
|
|
3
|
+
import { PostgresQueryCompiler } from "kysely";
|
|
4
|
+
import { BunSQLDriver } from "../sql";
|
|
5
|
+
|
|
6
|
+
export class PostgresDialect {
|
|
7
|
+
#config;
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
this.#config = config;
|
|
10
|
+
}
|
|
11
|
+
createDriver() {
|
|
12
|
+
return new BunSQLDriver({
|
|
13
|
+
adapter: "postgres",
|
|
14
|
+
...this.#config
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
createQueryCompiler() {
|
|
18
|
+
return new PostgresQueryCompiler;
|
|
19
|
+
}
|
|
20
|
+
createAdapter() {
|
|
21
|
+
return new PostgresAdapter;
|
|
22
|
+
}
|
|
23
|
+
createIntrospector(db) {
|
|
24
|
+
return new PostgresIntrospector(db);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default PostgresDialect;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DatabaseConnection, Driver, TransactionSettings } from "kysely";
|
|
2
|
+
import type { BunSQLDriverConfig } from "./types";
|
|
3
|
+
export declare class BunSQLDriver implements Driver {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(config: BunSQLDriverConfig);
|
|
6
|
+
init(): Promise<void>;
|
|
7
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
8
|
+
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
|
9
|
+
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
10
|
+
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
11
|
+
releaseConnection(_connection: DatabaseConnection): Promise<void>;
|
|
12
|
+
destroy(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SqliteAdapter } from "kysely";
|
|
2
|
+
import { SqliteIntrospector } from "kysely";
|
|
3
|
+
import { SqliteQueryCompiler } from "kysely";
|
|
4
|
+
import { BunSQLDriver } from "../sql";
|
|
5
|
+
|
|
6
|
+
export class SQLiteDialect {
|
|
7
|
+
#config;
|
|
8
|
+
constructor(config = {}) {
|
|
9
|
+
this.#config = config;
|
|
10
|
+
}
|
|
11
|
+
createDriver() {
|
|
12
|
+
return new BunSQLDriver({
|
|
13
|
+
adapter: "sqlite",
|
|
14
|
+
...this.#config
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
createQueryCompiler() {
|
|
18
|
+
return new SqliteQueryCompiler;
|
|
19
|
+
}
|
|
20
|
+
createAdapter() {
|
|
21
|
+
return new SqliteAdapter;
|
|
22
|
+
}
|
|
23
|
+
createIntrospector(db) {
|
|
24
|
+
return new SqliteIntrospector(db);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default SQLiteDialect;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SQL } from "bun";
|
|
2
|
+
export interface BunSQLDialectConfig {
|
|
3
|
+
url?: string | URL;
|
|
4
|
+
options?: ConstructorParameters<typeof SQL>[0];
|
|
5
|
+
}
|
|
6
|
+
/** @internal */
|
|
7
|
+
export interface BunSQLDriverConfig extends BunSQLDialectConfig {
|
|
8
|
+
adapter: "postgres" | "mysql" | "sqlite";
|
|
9
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
export*from"kysely";import{CompiledQuery as z}from"kysely";var{SQL:A}=globalThis.Bun;class E{#h;#x;constructor(x){this.#h=x}async init(){let{url:x,options:h}=this.#h;if(x)this.#x=new A(x,h??{});else if(h)this.#x=new A(h);else throw Error("Either url or options must be provided");await this.#x.connect()}async acquireConnection(){if(!this.#x)throw Error("Driver not initialized. Call init() first.");return new D(this.#x)}async beginTransaction(x,h){if(h.isolationLevel||h.accessMode){let j="start transaction";if(h.isolationLevel)j+=` isolation level ${h.isolationLevel}`;if(h.accessMode)j+=` ${h.accessMode}`;await x.executeQuery(z.raw(j))}else await x.executeQuery(z.raw("begin"))}async commitTransaction(x){await x.executeQuery(z.raw("commit"))}async rollbackTransaction(x){await x.executeQuery(z.raw("rollback"))}async releaseConnection(x){}async destroy(){if(this.#x)await this.#x.end(),this.#x=void 0}}class D{#h;constructor(x){this.#h=x}async executeQuery(x){let{sql:h,parameters:j}=x,v=await this.#h.unsafe(h,[...j]);return{rows:Array.isArray(v)?v:v?[v]:[]}}streamQuery(x,h){throw Error("Streaming queries are not supported")}}export{E as BunSQLDriver};
|
package/dist/sql.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DatabaseConnection, Driver, TransactionSettings } from "kysely";
|
|
2
|
+
import type { BunSQLDriverConfig } from "./types";
|
|
3
|
+
export declare class BunSQLDriver implements Driver {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(config: BunSQLDriverConfig);
|
|
6
|
+
init(): Promise<void>;
|
|
7
|
+
acquireConnection(): Promise<DatabaseConnection>;
|
|
8
|
+
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
|
|
9
|
+
commitTransaction(connection: DatabaseConnection): Promise<void>;
|
|
10
|
+
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
|
|
11
|
+
releaseConnection(_connection: DatabaseConnection): Promise<void>;
|
|
12
|
+
destroy(): Promise<void>;
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bunit/qb",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Kysely dialects powered by Bun's native SQL client for PostgreSQL, MySQL, and SQLite",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"bun",
|
|
7
|
+
"database",
|
|
8
|
+
"dialect",
|
|
9
|
+
"kysely",
|
|
10
|
+
"mariadb",
|
|
11
|
+
"mysql",
|
|
12
|
+
"orm",
|
|
13
|
+
"postgres",
|
|
14
|
+
"postgresql",
|
|
15
|
+
"query-builder",
|
|
16
|
+
"sql",
|
|
17
|
+
"sqlite"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/DemoMacro/BunIt#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/DemoMacro/BunIt/issues"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Demo Macro",
|
|
26
|
+
"email": "abc@imst.xyz",
|
|
27
|
+
"url": "https://www.demomacro.com/"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/DemoMacro/BunIt.git"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"main": "dist/index.mjs",
|
|
37
|
+
"types": "dist/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./dialects/*": {
|
|
44
|
+
"types": "./dist/dialects/*.d.ts",
|
|
45
|
+
"import": "./dist/dialects/*.mjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"dev": "built --stub",
|
|
50
|
+
"build": "built",
|
|
51
|
+
"prepack": "bun run build"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {},
|
|
54
|
+
"devDependencies": {},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"kysely": "^0.28.11"
|
|
57
|
+
}
|
|
58
|
+
}
|