@bunit/qb 0.0.0 → 0.0.3

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 CHANGED
@@ -1,88 +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) &copy; [Demo Macro](https://www.demomacro.com/)
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) &copy; [Demo Macro](https://www.demomacro.com/)
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{CompiledQuery as z}from"kysely";var{SQL:A}=globalThis.Bun;class E{#j;#h;constructor(h){this.#j=h}async init(){let{url:h,options:j}=this.#j;if(h)this.#h=new A(h,j??{});else if(j)this.#h=new A(j);else throw Error("Either url or options must be provided");await this.#h.connect()}async acquireConnection(){if(!this.#h)throw Error("Driver not initialized. Call init() first.");return new D(this.#h)}async beginTransaction(h,j){if(j.isolationLevel||j.accessMode){let v="start transaction";if(j.isolationLevel)v+=` isolation level ${j.isolationLevel}`;if(j.accessMode)v+=` ${j.accessMode}`;await h.executeQuery(z.raw(v))}else await h.executeQuery(z.raw("begin"))}async commitTransaction(h){await h.executeQuery(z.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(z.raw("rollback"))}async releaseConnection(h){}async destroy(){if(this.#h)await this.#h.end(),this.#h=void 0}}class D{#j;constructor(h){this.#j=h}async executeQuery(h){let{sql:j,parameters:v}=h,x=await this.#j.unsafe(j,[...v]);return{rows:Array.isArray(x)?x:x?[x]:[]}}streamQuery(h,j){throw Error("Streaming queries are not supported")}}
3
+ export{E as a};
@@ -0,0 +1,12 @@
1
+ import type { Kysely, DatabaseIntrospector, Dialect, DialectAdapter, Driver, QueryCompiler } from "kysely";
2
+ import type { BunSQLDialectConfig } from "../types";
3
+ export interface MySQLDialectConfig extends BunSQLDialectConfig {}
4
+ export declare class MySQLDialect implements Dialect {
5
+ #private;
6
+ constructor(config?: MySQLDialectConfig);
7
+ createDriver(): Driver;
8
+ createQueryCompiler(): QueryCompiler;
9
+ createAdapter(): DialectAdapter;
10
+ createIntrospector(db: Kysely<any>): DatabaseIntrospector;
11
+ }
12
+ export default MySQLDialect;
@@ -1,27 +1,2 @@
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;
1
+ // @bun
2
+ import{a as r}from"./_chunks/mysql-x4fwf4rk.mjs";import{MysqlAdapter as o,MysqlIntrospector as i,MysqlQueryCompiler as a}from"kysely";class t{#e;constructor(e={}){this.#e=e}createDriver(){return new r({adapter:"mysql",...this.#e})}createQueryCompiler(){return new a}createAdapter(){return new o}createIntrospector(e){return new i(e)}}var c=t;export{c as default,t as MySQLDialect};
@@ -0,0 +1,12 @@
1
+ import type { Kysely, DatabaseIntrospector, Dialect, DialectAdapter, Driver, QueryCompiler } from "kysely";
2
+ import type { BunSQLDialectConfig } from "../types";
3
+ export interface PostgresDialectConfig extends BunSQLDialectConfig {}
4
+ export declare class PostgresDialect implements Dialect {
5
+ #private;
6
+ constructor(config?: PostgresDialectConfig);
7
+ createDriver(): Driver;
8
+ createQueryCompiler(): QueryCompiler;
9
+ createAdapter(): DialectAdapter;
10
+ createIntrospector(db: Kysely<any>): DatabaseIntrospector;
11
+ }
12
+ export default PostgresDialect;
@@ -1,27 +1,2 @@
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;
1
+ // @bun
2
+ import{a as r}from"./_chunks/mysql-x4fwf4rk.mjs";import{PostgresAdapter as o,PostgresIntrospector as i,PostgresQueryCompiler as s}from"kysely";class t{#e;constructor(e={}){this.#e=e}createDriver(){return new r({adapter:"postgres",...this.#e})}createQueryCompiler(){return new s}createAdapter(){return new o}createIntrospector(e){return new i(e)}}var c=t;export{c as default,t as PostgresDialect};
@@ -0,0 +1,12 @@
1
+ import type { Kysely, DatabaseIntrospector, Dialect, DialectAdapter, Driver, QueryCompiler } from "kysely";
2
+ import type { BunSQLDialectConfig } from "../types";
3
+ export interface SQLiteDialectConfig extends BunSQLDialectConfig {}
4
+ export declare class SQLiteDialect implements Dialect {
5
+ #private;
6
+ constructor(config?: SQLiteDialectConfig);
7
+ createDriver(): Driver;
8
+ createQueryCompiler(): QueryCompiler;
9
+ createAdapter(): DialectAdapter;
10
+ createIntrospector(db: Kysely<any>): DatabaseIntrospector;
11
+ }
12
+ export default SQLiteDialect;
@@ -1,27 +1,2 @@
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;
1
+ // @bun
2
+ import{a as t}from"./_chunks/mysql-x4fwf4rk.mjs";import{SqliteAdapter as i,SqliteIntrospector as o,SqliteQueryCompiler as a}from"kysely";class r{#e;constructor(e={}){this.#e=e}createDriver(){return new t({adapter:"sqlite",...this.#e})}createQueryCompiler(){return new a}createAdapter(){return new i}createIntrospector(e){return new o(e)}}var c=r;export{c as default,r as SQLiteDialect};
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "kysely";
2
2
  export * from "./sql";
3
+ export * from "./types";
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
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};
2
+ import{a as n}from"./sql.mjs";export*from"kysely";export{n as BunSQLDriver};
package/dist/sql.mjs ADDED
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ import{CompiledQuery as z}from"kysely";var{SQL:A}=globalThis.Bun;class E{#j;#h;constructor(h){this.#j=h}async init(){let{url:h,options:j}=this.#j;if(h)this.#h=new A(h,j??{});else if(j)this.#h=new A(j);else throw Error("Either url or options must be provided");await this.#h.connect()}async acquireConnection(){if(!this.#h)throw Error("Driver not initialized. Call init() first.");return new D(this.#h)}async beginTransaction(h,j){if(j.isolationLevel||j.accessMode){let v="start transaction";if(j.isolationLevel)v+=` isolation level ${j.isolationLevel}`;if(j.accessMode)v+=` ${j.accessMode}`;await h.executeQuery(z.raw(v))}else await h.executeQuery(z.raw("begin"))}async commitTransaction(h){await h.executeQuery(z.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(z.raw("rollback"))}async releaseConnection(h){}async destroy(){if(this.#h)await this.#h.end(),this.#h=void 0}}class D{#j;constructor(h){this.#j=h}async executeQuery(h){let{sql:j,parameters:v}=h,x=await this.#j.unsafe(j,[...v]);return{rows:Array.isArray(x)?x:x?[x]:[]}}streamQuery(h,j){throw Error("Streaming queries are not supported")}}export{E as BunSQLDriver};
3
+ export{E as a};
@@ -1,9 +1,9 @@
1
1
  import type { SQL } from "bun";
2
2
  export interface BunSQLDialectConfig {
3
- url?: string | URL;
4
- options?: ConstructorParameters<typeof SQL>[0];
3
+ url?: string | URL;
4
+ options?: ConstructorParameters<typeof SQL>[0];
5
5
  }
6
6
  /** @internal */
7
7
  export interface BunSQLDriverConfig extends BunSQLDialectConfig {
8
- adapter: "postgres" | "mysql" | "sqlite";
8
+ adapter: "postgres" | "mysql" | "sqlite";
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunit/qb",
3
- "version": "0.0.0",
3
+ "version": "0.0.3",
4
4
  "description": "Kysely dialects powered by Bun's native SQL client for PostgreSQL, MySQL, and SQLite",
5
5
  "keywords": [
6
6
  "bun",
@@ -1,14 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;
@@ -1,13 +0,0 @@
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
- }