driftsql 1.0.0 → 1.0.1
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 +4 -60
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +36 -2
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -23,7 +23,6 @@ A lightweight SQL client for TypeScript, supporting multiple databases like Post
|
|
|
23
23
|
- **PostgreSQL** - Native PostgreSQL driver via `pg`
|
|
24
24
|
- **LibSQL** - SQLite-compatible databases via `@libsql/client`
|
|
25
25
|
- **HTTP** - HTTP-based database services
|
|
26
|
-
- **Neon** - Neon serverless PostgreSQL (experimental)
|
|
27
26
|
|
|
28
27
|
## Usage
|
|
29
28
|
|
|
@@ -44,12 +43,6 @@ Import and use:
|
|
|
44
43
|
import { DriftSQLClient } from 'driftsql'
|
|
45
44
|
```
|
|
46
45
|
|
|
47
|
-
**CDN** (Deno, Bun and Browsers)
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
import { DriftSQLClient } from 'https://esm.sh/driftsql'
|
|
51
|
-
```
|
|
52
|
-
|
|
53
46
|
<!-- /automd -->
|
|
54
47
|
|
|
55
48
|
## Quick Start
|
|
@@ -160,8 +153,6 @@ console.log(`Database OK: ${status.ok}, Ping: ${status.ping}ms`)
|
|
|
160
153
|
await db.close()
|
|
161
154
|
```
|
|
162
155
|
|
|
163
|
-
## API Reference
|
|
164
|
-
|
|
165
156
|
### Constructor Options
|
|
166
157
|
|
|
167
158
|
```typescript
|
|
@@ -182,62 +173,15 @@ interface ClientOptions {
|
|
|
182
173
|
}
|
|
183
174
|
```
|
|
184
175
|
|
|
185
|
-
### Methods
|
|
186
|
-
|
|
187
|
-
- `query<T>(sql: string, args?: (string | number | boolean | null)[])` - Execute raw SQL with parameters
|
|
188
|
-
- `findFirst<K>(table: K, where?: Partial<DT[K]>)` - Find first matching record
|
|
189
|
-
- `findMany<K>(table: K, where?: Partial<DT[K]>)` - Find all matching records
|
|
190
|
-
- `insert<K>(table: K, data: Partial<DT[K]>)` - Insert new record
|
|
191
|
-
- `update<K>(table: K, data: Partial<DT[K]>, where: Partial<DT[K]>)` - Update records
|
|
192
|
-
- `delete<K>(table: K, where: Partial<DT[K]>)` - Delete records
|
|
193
|
-
- `deleteFirst<K>(table: K, where: Partial<DT[K]>)` - Delete first matching record
|
|
194
|
-
- `status()` - Get server status and ping (HTTP driver only)
|
|
195
|
-
- `close()` - Close database connections
|
|
196
|
-
|
|
197
|
-
### Return Types
|
|
198
|
-
|
|
199
|
-
All query methods return a unified result format:
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
type UnifiedQueryResult<T> = {
|
|
203
|
-
rows: T[]
|
|
204
|
-
rowCount: number
|
|
205
|
-
command?: string
|
|
206
|
-
fields?: Array<{ name: string; dataTypeID: number }>
|
|
207
|
-
}
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## Development
|
|
211
|
-
|
|
212
|
-
<details>
|
|
213
|
-
|
|
214
|
-
<summary>local development</summary>
|
|
215
|
-
|
|
216
|
-
- Clone this repository
|
|
217
|
-
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
|
|
218
|
-
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
|
|
219
|
-
- Install dependencies using `pnpm install`
|
|
220
|
-
- Run interactive tests using `pnpm dev`
|
|
221
|
-
|
|
222
176
|
</details>
|
|
223
177
|
|
|
224
178
|
## License
|
|
225
179
|
|
|
226
180
|
<!-- automd:contributors license=MIT -->
|
|
227
181
|
|
|
228
|
-
Published under the [MIT](https://github.com/lassejlv/
|
|
229
|
-
Made by [community](https://github.com/lassejlv/
|
|
182
|
+
Published under the [MIT](https://github.com/lassejlv/driftsql/blob/main/LICENSE) license.
|
|
183
|
+
Made by [community](https://github.com/lassejlv/driftsql/graphs/contributors) 💛
|
|
230
184
|
<br><br>
|
|
231
|
-
<a href="https://github.com/lassejlv/
|
|
232
|
-
<img src="https://contrib.rocks/image?repo=lassejlv/
|
|
185
|
+
<a href="https://github.com/lassejlv/driftsql/graphs/contributors">
|
|
186
|
+
<img src="https://contrib.rocks/image?repo=lassejlv/driftsql" />
|
|
233
187
|
</a>
|
|
234
|
-
|
|
235
|
-
<!-- /automd -->
|
|
236
|
-
|
|
237
|
-
<!-- automd:with-automd -->
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
_🤖 auto updated with [automd](https://automd.unjs.io)_
|
|
242
|
-
|
|
243
|
-
<!-- /automd -->
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PoolConfig } from 'pg';
|
|
2
2
|
import { Config } from '@libsql/client';
|
|
3
|
+
import mysql from 'mysql2/promise';
|
|
3
4
|
|
|
4
5
|
type UnifiedQueryResult<T extends Record<string, any>> = {
|
|
5
6
|
rows: T[];
|
|
@@ -16,10 +17,7 @@ interface ClientOptions {
|
|
|
16
17
|
drivers?: {
|
|
17
18
|
libsql?: Config;
|
|
18
19
|
postgres?: PoolConfig;
|
|
19
|
-
|
|
20
|
-
postgresNeonHTTP?: {
|
|
21
|
-
connectionString: string;
|
|
22
|
-
};
|
|
20
|
+
mysql?: mysql.ConnectionOptions;
|
|
23
21
|
};
|
|
24
22
|
options?: {
|
|
25
23
|
defaultTimeout?: number;
|
|
@@ -28,8 +26,10 @@ interface ClientOptions {
|
|
|
28
26
|
declare class DriftSQLClient<DT> {
|
|
29
27
|
private client;
|
|
30
28
|
private pool?;
|
|
29
|
+
private mysqlClient?;
|
|
31
30
|
private libsqlClient?;
|
|
32
31
|
private neonClient?;
|
|
32
|
+
private postgresClient?;
|
|
33
33
|
constructor(options: ClientOptions);
|
|
34
34
|
private convertLibsqlResult;
|
|
35
35
|
query<T extends Record<string, any>>(query: string, args?: (string | number | boolean | null)[]): Promise<UnifiedQueryResult<T>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PoolConfig } from 'pg';
|
|
2
2
|
import { Config } from '@libsql/client';
|
|
3
|
+
import mysql from 'mysql2/promise';
|
|
3
4
|
|
|
4
5
|
type UnifiedQueryResult<T extends Record<string, any>> = {
|
|
5
6
|
rows: T[];
|
|
@@ -16,10 +17,7 @@ interface ClientOptions {
|
|
|
16
17
|
drivers?: {
|
|
17
18
|
libsql?: Config;
|
|
18
19
|
postgres?: PoolConfig;
|
|
19
|
-
|
|
20
|
-
postgresNeonHTTP?: {
|
|
21
|
-
connectionString: string;
|
|
22
|
-
};
|
|
20
|
+
mysql?: mysql.ConnectionOptions;
|
|
23
21
|
};
|
|
24
22
|
options?: {
|
|
25
23
|
defaultTimeout?: number;
|
|
@@ -28,8 +26,10 @@ interface ClientOptions {
|
|
|
28
26
|
declare class DriftSQLClient<DT> {
|
|
29
27
|
private client;
|
|
30
28
|
private pool?;
|
|
29
|
+
private mysqlClient?;
|
|
31
30
|
private libsqlClient?;
|
|
32
31
|
private neonClient?;
|
|
32
|
+
private postgresClient?;
|
|
33
33
|
constructor(options: ClientOptions);
|
|
34
34
|
private convertLibsqlResult;
|
|
35
35
|
query<T extends Record<string, any>>(query: string, args?: (string | number | boolean | null)[]): Promise<UnifiedQueryResult<T>>;
|
package/dist/index.mjs
CHANGED
|
@@ -2,13 +2,15 @@ import consola from 'consola';
|
|
|
2
2
|
import ky from 'ky';
|
|
3
3
|
import { Pool } from 'pg';
|
|
4
4
|
import { createClient } from '@libsql/client';
|
|
5
|
-
import
|
|
5
|
+
import mysql from 'mysql2/promise';
|
|
6
6
|
|
|
7
7
|
class DriftSQLClient {
|
|
8
8
|
client;
|
|
9
9
|
pool;
|
|
10
|
+
mysqlClient;
|
|
10
11
|
libsqlClient;
|
|
11
12
|
neonClient;
|
|
13
|
+
postgresClient;
|
|
12
14
|
constructor(options) {
|
|
13
15
|
this.client = ky.create({
|
|
14
16
|
prefixUrl: options.url,
|
|
@@ -30,7 +32,7 @@ class DriftSQLClient {
|
|
|
30
32
|
});
|
|
31
33
|
this.pool = options.drivers?.postgres ? new Pool(options.drivers.postgres) : void 0;
|
|
32
34
|
this.libsqlClient = options.drivers?.libsql ? createClient(options.drivers.libsql) : void 0;
|
|
33
|
-
this.
|
|
35
|
+
this.mysqlClient = options.drivers?.mysql ? mysql.createConnection(options.drivers.mysql) : void 0;
|
|
34
36
|
}
|
|
35
37
|
convertLibsqlResult(result) {
|
|
36
38
|
const rows = result.rows.map((row) => {
|
|
@@ -62,6 +64,38 @@ class DriftSQLClient {
|
|
|
62
64
|
consola.error("Failed to connect to PostgreSQL pool:", error);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
if (this.mysqlClient) {
|
|
68
|
+
try {
|
|
69
|
+
consola.warn("MySQL client is experimental and may not be compatible with the helper functions, since they originally designed for PostgreSQL and libsql. But .query() method should work.");
|
|
70
|
+
const [rows, fields] = await (await this.mysqlClient).execute(query, args || []);
|
|
71
|
+
return {
|
|
72
|
+
rows,
|
|
73
|
+
rowCount: Array.isArray(rows) ? rows.length : 0,
|
|
74
|
+
command: void 0,
|
|
75
|
+
// MySQL does not return command info
|
|
76
|
+
fields: fields.map((field) => ({ name: field.name, dataTypeID: field.columnType }))
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
consola.error("Failed to execute query with MySQL:", error);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (this.postgresClient) {
|
|
84
|
+
try {
|
|
85
|
+
const result = await this.postgresClient.unsafe(query, args || []);
|
|
86
|
+
return {
|
|
87
|
+
// @ts-ignore - postgres library returns rows directly
|
|
88
|
+
rows: result,
|
|
89
|
+
rowCount: result.length,
|
|
90
|
+
command: void 0,
|
|
91
|
+
fields: []
|
|
92
|
+
// postgres library does not provide field info
|
|
93
|
+
};
|
|
94
|
+
} catch (error) {
|
|
95
|
+
consola.error("Failed to execute query with postgres:", error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
65
99
|
if (this.libsqlClient) {
|
|
66
100
|
try {
|
|
67
101
|
const result = await this.libsqlClient.execute({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "driftsql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"author": "lasse vestergaard",
|
|
5
5
|
"description": "A lightweight SQL client for TypeScript, supporting multiple databases like PostgreSQL, MySQL, and LibSQL.",
|
|
6
6
|
"repository": "lassejlv/driftsql",
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
"driftsql": "^0.0.1",
|
|
48
48
|
"drizzle-orm": "^0.44.2",
|
|
49
49
|
"ky": "^1.8.1",
|
|
50
|
-
"
|
|
50
|
+
"mysql2": "^3.14.1",
|
|
51
|
+
"pg": "^8.16.0",
|
|
52
|
+
"postgres": "^3.4.7"
|
|
51
53
|
}
|
|
52
54
|
}
|