Skip to content

Commit 9784e4d

Browse files
committed
chore: lint
1 parent 83f1425 commit 9784e4d

22 files changed

+349
-273
lines changed

.prettierignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
connectors
2-
integrations
3-
src/_connectors.ts
4-
dist
5-
node_modules
6-
.output
1+
/connectors
2+
/integrations
3+
/src/_connectors.ts
4+
/dist
5+
/node_modules
6+
/.output
7+
pnpm-lock.yaml

src/connectors/better-sqlite3.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { resolve, dirname } from "node:path";
22
import { mkdirSync } from "node:fs";
33
import Database from "better-sqlite3";
44
import type { Connector } from "db0";
5-
import type { Statement as RawStatement } from 'better-sqlite3'
5+
import type { Statement as RawStatement } from "better-sqlite3";
66
import { BoundableStatement } from "./_internal/statement";
77

88
export interface ConnectorOptions {
@@ -11,7 +11,9 @@ export interface ConnectorOptions {
1111
name?: string;
1212
}
1313

14-
export default function sqliteConnector(opts: ConnectorOptions): Connector<Database.Database> {
14+
export default function sqliteConnector(
15+
opts: ConnectorOptions,
16+
): Connector<Database.Database> {
1517
let _db: Database.Database;
1618
const getDB = () => {
1719
if (_db) {
@@ -34,22 +36,22 @@ export default function sqliteConnector(opts: ConnectorOptions): Connector<Datab
3436
name: "sqlite",
3537
dialect: "sqlite",
3638
getInstance: () => getDB(),
37-
exec: sql => getDB().exec(sql),
38-
prepare: sql => new StatementWrapper(() => getDB().prepare(sql))
39+
exec: (sql) => getDB().exec(sql),
40+
prepare: (sql) => new StatementWrapper(() => getDB().prepare(sql)),
3941
};
4042
}
4143

4244
class StatementWrapper extends BoundableStatement<() => RawStatement> {
4345
async all(...params) {
44-
return this._statement().all(...params)
46+
return this._statement().all(...params);
4547
}
4648

4749
async run(...params) {
48-
const res = this._statement().run(...params)
49-
return { success: res.changes > 0, ...res }
50+
const res = this._statement().run(...params);
51+
return { success: res.changes > 0, ...res };
5052
}
5153

5254
async get(...params) {
53-
return this._statement().get(...params)
55+
return this._statement().get(...params);
5456
}
5557
}

src/connectors/bun-sqlite.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export interface ConnectorOptions {
1010
name?: string;
1111
}
1212

13-
export default function bunSqliteConnector(opts: ConnectorOptions): Connector<Database> {
13+
export default function bunSqliteConnector(
14+
opts: ConnectorOptions,
15+
): Connector<Database> {
1416
let _db: Database;
1517
const getDB = () => {
1618
if (_db) {
@@ -33,8 +35,8 @@ export default function bunSqliteConnector(opts: ConnectorOptions): Connector<Da
3335
name: "sqlite",
3436
dialect: "sqlite",
3537
getInstance: () => getDB(),
36-
exec: sql => getDB().exec(sql),
37-
prepare: sql => new StatementWrapper(getDB().prepare(sql))
38+
exec: (sql) => getDB().exec(sql),
39+
prepare: (sql) => new StatementWrapper(getDB().prepare(sql)),
3840
};
3941
}
4042

src/connectors/cloudflare-d1.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,52 @@
1-
import type { D1Database, D1PreparedStatement as RawStatement } from '@cloudflare/workers-types'
1+
import type {
2+
D1Database,
3+
D1PreparedStatement as RawStatement,
4+
} from "@cloudflare/workers-types";
25
import type { Connector } from "db0";
36
import { BoundableStatement } from "./_internal/statement";
47

58
export interface ConnectorOptions {
69
bindingName?: string;
710
}
811

9-
export default function cloudflareD1Connector(options: ConnectorOptions): Connector<D1Database> {
12+
export default function cloudflareD1Connector(
13+
options: ConnectorOptions,
14+
): Connector<D1Database> {
1015
const getDB = () => {
1116
// TODO: Remove legacy __cf_env__ support in next major version
12-
const binding: D1Database = globalThis.__env__?.[options.bindingName] || globalThis.__cf_env__?.[options.bindingName];
17+
const binding: D1Database =
18+
globalThis.__env__?.[options.bindingName] ||
19+
globalThis.__cf_env__?.[options.bindingName];
1320
if (!binding) {
14-
throw new Error(`[db0] [d1] binding \`${options.bindingName}\` not found`);
21+
throw new Error(
22+
`[db0] [d1] binding \`${options.bindingName}\` not found`,
23+
);
1524
}
1625
return binding;
17-
}
26+
};
1827

1928
return {
2029
name: "cloudflare-d1",
2130
dialect: "sqlite",
2231
getInstance: () => getDB(),
2332
exec: (sql) => getDB().exec(sql),
24-
prepare: sql => new StatementWrapper(getDB().prepare(sql))
33+
prepare: (sql) => new StatementWrapper(getDB().prepare(sql)),
2534
};
2635
}
2736

2837
class StatementWrapper extends BoundableStatement<RawStatement> {
2938
async all(...params) {
30-
const res = await this._statement.bind(...params).all()
31-
return res.results
39+
const res = await this._statement.bind(...params).all();
40+
return res.results;
3241
}
3342

3443
async run(...params) {
35-
const res = await this._statement.bind(...params).run()
36-
return res
44+
const res = await this._statement.bind(...params).run();
45+
return res;
3746
}
3847

3948
async get(...params) {
40-
const res = await this._statement.bind(...params).first()
41-
return res
49+
const res = await this._statement.bind(...params).first();
50+
return res;
4251
}
4352
}

src/connectors/libsql/core.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ export type ConnectorOptions = {
99

1010
type InternalQuery = (sql: InStatement) => Promise<any>;
1111

12-
export default function libSqlCoreConnector(opts: ConnectorOptions): Connector<Client> {
12+
export default function libSqlCoreConnector(
13+
opts: ConnectorOptions,
14+
): Connector<Client> {
1315
const query: InternalQuery = (sql) => opts.getClient().execute(sql);
1416

1517
return {
1618
name: opts.name || "libsql-core",
1719
dialect: "libsql",
1820
getInstance: async () => opts.getClient(),
19-
exec: sql => query(sql),
21+
exec: (sql) => query(sql),
2022
prepare: (sql) => new StatementWrapper(sql, query),
2123
};
2224
}
@@ -32,19 +34,19 @@ class StatementWrapper extends BoundableStatement<void> {
3234
}
3335

3436
async all(...params) {
35-
const res = await this.#query({ sql: this.#sql, args: params })
37+
const res = await this.#query({ sql: this.#sql, args: params });
3638
return res.rows;
3739
}
3840

3941
async run(...params) {
40-
const res = await this.#query({ sql: this.#sql, args: params })
42+
const res = await this.#query({ sql: this.#sql, args: params });
4143
return {
42-
...res
43-
}
44+
...res,
45+
};
4446
}
4547

4648
async get(...params) {
47-
const res = await this.#query({ sql: this.#sql, args: params })
49+
const res = await this.#query({ sql: this.#sql, args: params });
4850
return res.rows[0];
4951
}
5052
}

src/connectors/libsql/http.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import type { Connector } from "db0";
33
import { createClient } from "@libsql/client/http";
44
import libSqlCore from "./core";
55

6-
76
export type ConnectorOptions = Config;
87

9-
export default function libSqlConnector(opts: ConnectorOptions): Connector<Client> {
8+
export default function libSqlConnector(
9+
opts: ConnectorOptions,
10+
): Connector<Client> {
1011
let _client;
1112
const getClient = () => {
1213
if (!_client) {

src/connectors/libsql/node.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import libSqlCore from "./core";
55

66
export type ConnectorOptions = Config;
77

8-
export default function libSqlConnector(opts: ConnectorOptions): Connector<Client> {
8+
export default function libSqlConnector(
9+
opts: ConnectorOptions,
10+
): Connector<Client> {
911
let _client;
1012
const getClient = () => {
1113
if (!_client) {

src/connectors/libsql/web.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import libSqlCore from "./core";
55

66
export type ConnectorOptions = Config;
77

8-
export default function libSqlConnector(opts: ConnectorOptions): Connector<Client> {
8+
export default function libSqlConnector(
9+
opts: ConnectorOptions,
10+
): Connector<Client> {
911
let _client;
1012
const getClient = () => {
1113
if (!_client) {

src/connectors/mysql2.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import mysql from "mysql2/promise";
22
import type { Connector } from "db0";
33
import { BoundableStatement } from "./_internal/statement";
44

5-
export type ConnectorOptions = mysql.ConnectionOptions
5+
export type ConnectorOptions = mysql.ConnectionOptions;
66

7-
type InternalQuery = (sql: string, params?: unknown[]) => Promise<mysql.QueryResult>
7+
type InternalQuery = (
8+
sql: string,
9+
params?: unknown[],
10+
) => Promise<mysql.QueryResult>;
811

9-
export default function mysqlConnector(opts: ConnectorOptions): Connector<mysql.Connection> {
12+
export default function mysqlConnector(
13+
opts: ConnectorOptions,
14+
): Connector<mysql.Connection> {
1015
let _connection: mysql.Connection | undefined;
1116
const getConnection = async () => {
1217
if (_connection) {
@@ -15,19 +20,22 @@ export default function mysqlConnector(opts: ConnectorOptions): Connector<mysql.
1520

1621
_connection = await mysql.createConnection({
1722
...opts,
18-
})
23+
});
1924

2025
return _connection;
2126
};
2227

23-
const query: InternalQuery = (sql, params) => getConnection().then((c) => c.query(sql, params)).then((res) => res[0]);
28+
const query: InternalQuery = (sql, params) =>
29+
getConnection()
30+
.then((c) => c.query(sql, params))
31+
.then((res) => res[0]);
2432

2533
return {
2634
name: "mysql",
2735
dialect: "mysql",
2836
getInstance: () => getConnection(),
29-
exec: sql => query(sql),
30-
prepare: sql => new StatementWrapper(sql, query)
37+
exec: (sql) => query(sql),
38+
prepare: (sql) => new StatementWrapper(sql, query),
3139
};
3240
}
3341

@@ -42,20 +50,20 @@ class StatementWrapper extends BoundableStatement<void> {
4250
}
4351

4452
async all(...params) {
45-
const res = await this.#query(this.#sql, params) as mysql.RowDataPacket[]
46-
return res
53+
const res = (await this.#query(this.#sql, params)) as mysql.RowDataPacket[];
54+
return res;
4755
}
4856

4957
async run(...params) {
50-
const res = await this.#query(this.#sql, params) as mysql.RowDataPacket[]
58+
const res = (await this.#query(this.#sql, params)) as mysql.RowDataPacket[];
5159
return {
5260
success: true,
5361
...res,
54-
}
62+
};
5563
}
5664

5765
async get(...params) {
58-
const res = await this.#query(this.#sql, params) as mysql.RowDataPacket[]
59-
return res[0]
66+
const res = (await this.#query(this.#sql, params)) as mysql.RowDataPacket[];
67+
return res[0];
6068
}
6169
}

0 commit comments

Comments
 (0)