driftsql 1.0.11 → 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 CHANGED
@@ -1,15 +1,30 @@
1
+ type DriverOptions<T = object> = T & {
2
+ experimental?: Record<string, any>;
3
+ };
4
+
1
5
  interface PostgresConfig {
2
- connectionString: string;
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;
8
- options?: {
23
+ options?: DriverOptions<{
9
24
  experimental?: {
10
25
  useTursoServerlessDriver?: boolean;
11
26
  };
12
- };
27
+ }>;
13
28
  }
14
29
 
15
30
  interface MySQLConfig {
package/dist/index.d.ts CHANGED
@@ -1,15 +1,30 @@
1
+ type DriverOptions<T = object> = T & {
2
+ experimental?: Record<string, any>;
3
+ };
4
+
1
5
  interface PostgresConfig {
2
- connectionString: string;
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;
8
- options?: {
23
+ options?: DriverOptions<{
9
24
  experimental?: {
10
25
  useTursoServerlessDriver?: boolean;
11
26
  };
12
- };
27
+ }>;
13
28
  }
14
29
 
15
30
  interface MySQLConfig {
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import consola from 'consola';
2
2
  import postgres from 'postgres';
3
+ import ky from 'ky';
3
4
  import { createClient as createClient$1 } from '@libsql/client';
4
5
  import { createClient } from '@tursodatabase/serverless/compat';
5
6
  import * as mysql from 'mysql2/promise';
@@ -258,11 +259,18 @@ const inspectDB = async (drivers) => {
258
259
  class PostgresDriver {
259
260
  constructor(options) {
260
261
  this.options = options;
261
- this.client = postgres(this.options.connectionString);
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
+ }
262
267
  }
263
268
  client;
264
269
  async query(query, params) {
265
270
  try {
271
+ if (this.client instanceof PostgresHTTPDriver) {
272
+ return await this.client.query(query, params);
273
+ }
266
274
  const result = await this.client.unsafe(query, params);
267
275
  return {
268
276
  rows: result,
@@ -276,6 +284,9 @@ class PostgresDriver {
276
284
  }
277
285
  async close() {
278
286
  try {
287
+ if (this.client instanceof PostgresHTTPDriver) {
288
+ return await this.client.close();
289
+ }
279
290
  await this.client.end();
280
291
  } catch (error) {
281
292
  console.error("Error closing Postgres client:", error);
@@ -283,6 +294,41 @@ class PostgresDriver {
283
294
  }
284
295
  }
285
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
+ }
286
332
 
287
333
  class LibSQLDriver {
288
334
  constructor(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "driftsql",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "author": "lasse vestergaard",
5
5
  "description": "A lightweight SQL client for TypeScript",
6
6
  "repository": "lassejlv/driftsql",
@@ -42,6 +42,7 @@
42
42
  "dependencies": {
43
43
  "@libsql/client": "^0.15.9",
44
44
  "@neondatabase/serverless": "^1.0.1",
45
+ "@sqlitecloud/drivers": "^1.0.507",
45
46
  "@tursodatabase/serverless": "^0.1.2",
46
47
  "@types/pg": "^8.15.4",
47
48
  "consola": "^3.4.2",
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.