driftsql 1.0.10 → 1.0.12
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/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.mjs +53 -3
- package/package.json +4 -2
- package/LICENSE +0 -21
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
type DriverOptions<T = object> = T & {
|
|
2
|
+
experimental?: Record<string, any>;
|
|
3
|
+
};
|
|
4
|
+
|
|
1
5
|
interface PostgresConfig {
|
|
2
|
-
connectionString
|
|
6
|
+
connectionString?: string;
|
|
7
|
+
options?: DriverOptions<{
|
|
8
|
+
experimental?: {
|
|
9
|
+
/**
|
|
10
|
+
* Enable experimental postgres http support. Using github.com/lassejlv/postgres_http
|
|
11
|
+
*/
|
|
12
|
+
http?: {
|
|
13
|
+
url: string;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
3
18
|
}
|
|
4
19
|
|
|
5
20
|
interface LibSQLConfig {
|
|
6
21
|
url: string;
|
|
7
22
|
authToken?: string;
|
|
23
|
+
options?: DriverOptions<{
|
|
24
|
+
experimental?: {
|
|
25
|
+
useTursoServerlessDriver?: boolean;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
8
28
|
}
|
|
9
29
|
|
|
10
30
|
interface MySQLConfig {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
type DriverOptions<T = object> = T & {
|
|
2
|
+
experimental?: Record<string, any>;
|
|
3
|
+
};
|
|
4
|
+
|
|
1
5
|
interface PostgresConfig {
|
|
2
|
-
connectionString
|
|
6
|
+
connectionString?: string;
|
|
7
|
+
options?: DriverOptions<{
|
|
8
|
+
experimental?: {
|
|
9
|
+
/**
|
|
10
|
+
* Enable experimental postgres http support. Using github.com/lassejlv/postgres_http
|
|
11
|
+
*/
|
|
12
|
+
http?: {
|
|
13
|
+
url: string;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
3
18
|
}
|
|
4
19
|
|
|
5
20
|
interface LibSQLConfig {
|
|
6
21
|
url: string;
|
|
7
22
|
authToken?: string;
|
|
23
|
+
options?: DriverOptions<{
|
|
24
|
+
experimental?: {
|
|
25
|
+
useTursoServerlessDriver?: boolean;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
8
28
|
}
|
|
9
29
|
|
|
10
30
|
interface MySQLConfig {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import consola from 'consola';
|
|
2
2
|
import postgres from 'postgres';
|
|
3
|
-
import
|
|
3
|
+
import ky from 'ky';
|
|
4
|
+
import { createClient as createClient$1 } from '@libsql/client';
|
|
5
|
+
import { createClient } from '@tursodatabase/serverless/compat';
|
|
4
6
|
import * as mysql from 'mysql2/promise';
|
|
5
7
|
import fs from 'node:fs/promises';
|
|
6
8
|
|
|
@@ -257,11 +259,18 @@ const inspectDB = async (drivers) => {
|
|
|
257
259
|
class PostgresDriver {
|
|
258
260
|
constructor(options) {
|
|
259
261
|
this.options = options;
|
|
260
|
-
|
|
262
|
+
if (this.options.options?.experimental?.http) {
|
|
263
|
+
this.client = new PostgresHTTPDriver(this.options.options.experimental);
|
|
264
|
+
} else {
|
|
265
|
+
this.client = postgres(this.options.connectionString || "");
|
|
266
|
+
}
|
|
261
267
|
}
|
|
262
268
|
client;
|
|
263
269
|
async query(query, params) {
|
|
264
270
|
try {
|
|
271
|
+
if (this.client instanceof PostgresHTTPDriver) {
|
|
272
|
+
return await this.client.query(query, params);
|
|
273
|
+
}
|
|
265
274
|
const result = await this.client.unsafe(query, params);
|
|
266
275
|
return {
|
|
267
276
|
rows: result,
|
|
@@ -275,6 +284,9 @@ class PostgresDriver {
|
|
|
275
284
|
}
|
|
276
285
|
async close() {
|
|
277
286
|
try {
|
|
287
|
+
if (this.client instanceof PostgresHTTPDriver) {
|
|
288
|
+
return await this.client.close();
|
|
289
|
+
}
|
|
278
290
|
await this.client.end();
|
|
279
291
|
} catch (error) {
|
|
280
292
|
console.error("Error closing Postgres client:", error);
|
|
@@ -282,11 +294,49 @@ class PostgresDriver {
|
|
|
282
294
|
}
|
|
283
295
|
}
|
|
284
296
|
}
|
|
297
|
+
class PostgresHTTPDriver {
|
|
298
|
+
httpClient;
|
|
299
|
+
constructor(options) {
|
|
300
|
+
if (!options || !options.http || !options.http.url) {
|
|
301
|
+
throw new Error("Postgres HTTP driver requires a valid URL in options.http");
|
|
302
|
+
}
|
|
303
|
+
this.httpClient = ky.create({
|
|
304
|
+
prefixUrl: options.http.url,
|
|
305
|
+
headers: {
|
|
306
|
+
Authorization: `Bearer ${options.http.apiKey || ""}`
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
async query(query, params) {
|
|
311
|
+
try {
|
|
312
|
+
const response = await this.httpClient.post("query", {
|
|
313
|
+
json: {
|
|
314
|
+
query,
|
|
315
|
+
params
|
|
316
|
+
}
|
|
317
|
+
}).json();
|
|
318
|
+
return {
|
|
319
|
+
rows: response.rows,
|
|
320
|
+
rowCount: response.rowCount,
|
|
321
|
+
command: void 0
|
|
322
|
+
};
|
|
323
|
+
} catch (error) {
|
|
324
|
+
console.error("Postgres HTTP query error:", error);
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
async close() {
|
|
329
|
+
return Promise.resolve();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
285
332
|
|
|
286
333
|
class LibSQLDriver {
|
|
287
334
|
constructor(options) {
|
|
288
335
|
this.options = options;
|
|
289
|
-
this.client = createClient({
|
|
336
|
+
this.client = this.options?.options?.experimental?.useTursoServerlessDriver ? createClient({
|
|
337
|
+
url: this.options.url,
|
|
338
|
+
...this.options.authToken ? { authToken: this.options.authToken } : {}
|
|
339
|
+
}) : createClient$1({
|
|
290
340
|
url: this.options.url,
|
|
291
341
|
...this.options.authToken ? { authToken: this.options.authToken } : {}
|
|
292
342
|
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "driftsql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"author": "lasse vestergaard",
|
|
5
|
-
"description": "A lightweight SQL client for TypeScript
|
|
5
|
+
"description": "A lightweight SQL client for TypeScript",
|
|
6
6
|
"repository": "lassejlv/driftsql",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@libsql/client": "^0.15.9",
|
|
44
44
|
"@neondatabase/serverless": "^1.0.1",
|
|
45
|
+
"@sqlitecloud/drivers": "^1.0.507",
|
|
46
|
+
"@tursodatabase/serverless": "^0.1.2",
|
|
45
47
|
"@types/pg": "^8.15.4",
|
|
46
48
|
"consola": "^3.4.2",
|
|
47
49
|
"driftsql": "^0.0.1",
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Lasse Vestergaard
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|