driftsql 1.0.6 → 1.0.8
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 +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.mjs +22 -5
- package/package.json +8 -8
package/dist/index.d.mts
CHANGED
|
@@ -15,11 +15,21 @@ type UnifiedQueryResult<T extends Record<string, any>> = {
|
|
|
15
15
|
}>;
|
|
16
16
|
};
|
|
17
17
|
interface ClientOptions {
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Since version 1.0.8 this option is deprecated and will be removed in future versions. Use `drivers.postgresHTTP.url` instead.
|
|
20
|
+
*/
|
|
18
21
|
url?: string;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Since version 1.0.8 this option is deprecated and will be removed in future versions. Use `drivers.postgresHTTP.url` instead.
|
|
24
|
+
*/
|
|
19
25
|
password?: string;
|
|
20
26
|
drivers?: {
|
|
21
27
|
libsql?: Config;
|
|
22
28
|
postgres?: PoolConfig;
|
|
29
|
+
postgresHTTP?: {
|
|
30
|
+
url: string;
|
|
31
|
+
password: string;
|
|
32
|
+
};
|
|
23
33
|
mysql?: ConnectionOptions;
|
|
24
34
|
};
|
|
25
35
|
options?: {
|
package/dist/index.d.ts
CHANGED
|
@@ -15,11 +15,21 @@ type UnifiedQueryResult<T extends Record<string, any>> = {
|
|
|
15
15
|
}>;
|
|
16
16
|
};
|
|
17
17
|
interface ClientOptions {
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Since version 1.0.8 this option is deprecated and will be removed in future versions. Use `drivers.postgresHTTP.url` instead.
|
|
20
|
+
*/
|
|
18
21
|
url?: string;
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated Since version 1.0.8 this option is deprecated and will be removed in future versions. Use `drivers.postgresHTTP.url` instead.
|
|
24
|
+
*/
|
|
19
25
|
password?: string;
|
|
20
26
|
drivers?: {
|
|
21
27
|
libsql?: Config;
|
|
22
28
|
postgres?: PoolConfig;
|
|
29
|
+
postgresHTTP?: {
|
|
30
|
+
url: string;
|
|
31
|
+
password: string;
|
|
32
|
+
};
|
|
23
33
|
mysql?: ConnectionOptions;
|
|
24
34
|
};
|
|
25
35
|
options?: {
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { createClient } from '@libsql/client';
|
|
|
5
5
|
import mysql from 'mysql2/promise';
|
|
6
6
|
import fs from 'node:fs/promises';
|
|
7
7
|
|
|
8
|
-
const supportedDrivers = ["postgres", "mysql"];
|
|
8
|
+
const supportedDrivers = ["postgres", "postgresHTTP", "mysql", "libsql"];
|
|
9
9
|
const mapDatabaseTypeToTypeScript = (dataType, isNullable = false, driverType = "postgres") => {
|
|
10
10
|
const nullable = isNullable ? " | null" : "";
|
|
11
11
|
const lowerType = dataType.toLowerCase();
|
|
@@ -118,13 +118,19 @@ const inspectDB = async (drivers) => {
|
|
|
118
118
|
AND TABLE_TYPE = 'BASE TABLE'
|
|
119
119
|
ORDER BY TABLE_NAME`;
|
|
120
120
|
tableSchemaFilter = currentDatabase;
|
|
121
|
-
} else {
|
|
121
|
+
} else if (activeDriver === "postgres" || activeDriver === "postgresHTTP") {
|
|
122
122
|
tablesQuery = `SELECT table_name
|
|
123
123
|
FROM information_schema.tables
|
|
124
124
|
WHERE table_schema = $1
|
|
125
125
|
AND table_type = 'BASE TABLE'
|
|
126
126
|
ORDER BY table_name`;
|
|
127
127
|
tableSchemaFilter = "public";
|
|
128
|
+
} else {
|
|
129
|
+
tablesQuery = `SELECT name as table_name
|
|
130
|
+
FROM sqlite_master
|
|
131
|
+
WHERE type = 'table'
|
|
132
|
+
ORDER BY name`;
|
|
133
|
+
tableSchemaFilter = void 0;
|
|
128
134
|
}
|
|
129
135
|
const tables = await client.query(tablesQuery, tableSchemaFilter ? [tableSchemaFilter] : []);
|
|
130
136
|
console.log("Tables in the database:", tables.rows.map((t) => t.table_name).join(", "));
|
|
@@ -146,7 +152,7 @@ const inspectDB = async (drivers) => {
|
|
|
146
152
|
ORDER BY ORDINAL_POSITION
|
|
147
153
|
`;
|
|
148
154
|
queryParams = [tableName, tableSchemaFilter];
|
|
149
|
-
} else {
|
|
155
|
+
} else if (activeDriver === "postgres" || activeDriver === "postgresHTTP") {
|
|
150
156
|
columnsQuery = `
|
|
151
157
|
SELECT
|
|
152
158
|
column_name,
|
|
@@ -159,6 +165,17 @@ const inspectDB = async (drivers) => {
|
|
|
159
165
|
ORDER BY ordinal_position
|
|
160
166
|
`;
|
|
161
167
|
queryParams = [tableName, tableSchemaFilter];
|
|
168
|
+
} else {
|
|
169
|
+
columnsQuery = `
|
|
170
|
+
SELECT
|
|
171
|
+
name as column_name,
|
|
172
|
+
type as data_type,
|
|
173
|
+
CASE WHEN "notnull" = 0 THEN 'YES' ELSE 'NO' END as is_nullable,
|
|
174
|
+
dflt_value as column_default
|
|
175
|
+
FROM pragma_table_info(?)
|
|
176
|
+
ORDER BY cid
|
|
177
|
+
`;
|
|
178
|
+
queryParams = [tableName];
|
|
162
179
|
}
|
|
163
180
|
const columns = await client.query(columnsQuery, queryParams);
|
|
164
181
|
if (columns.rows.length === 0) {
|
|
@@ -202,9 +219,9 @@ class DriftSQLClient {
|
|
|
202
219
|
drivers;
|
|
203
220
|
constructor(options) {
|
|
204
221
|
this.client = ky.create({
|
|
205
|
-
prefixUrl: options.url,
|
|
222
|
+
prefixUrl: options.drivers?.postgresHTTP.url || options.url || "http://localhost:3000",
|
|
206
223
|
headers: {
|
|
207
|
-
Authorization: `Bearer ${options.password}`
|
|
224
|
+
Authorization: `Bearer ${options.drivers?.postgresHTTP?.password || options.password || ""}`
|
|
208
225
|
},
|
|
209
226
|
timeout: options.options?.defaultTimeout || 5e3,
|
|
210
227
|
hooks: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "driftsql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
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",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"test:types": "tsc --noEmit --skipLibCheck"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@types/node": "^22.
|
|
31
|
-
"@vitest/coverage-v8": "^3.
|
|
30
|
+
"@types/node": "^22.15.34",
|
|
31
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
32
32
|
"automd": "^0.4.0",
|
|
33
33
|
"changelogen": "^0.6.1",
|
|
34
|
-
"eslint": "^9.
|
|
34
|
+
"eslint": "^9.30.0",
|
|
35
35
|
"eslint-config-unjs": "^0.4.2",
|
|
36
|
-
"prettier": "^3.
|
|
37
|
-
"typescript": "^5.8.
|
|
36
|
+
"prettier": "^3.6.2",
|
|
37
|
+
"typescript": "^5.8.3",
|
|
38
38
|
"unbuild": "^3.5.0",
|
|
39
|
-
"vitest": "^3.
|
|
39
|
+
"vitest": "^3.2.4"
|
|
40
40
|
},
|
|
41
41
|
"packageManager": "pnpm@10.12.1",
|
|
42
42
|
"dependencies": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"drizzle-orm": "^0.44.2",
|
|
49
49
|
"ky": "^1.8.1",
|
|
50
50
|
"mysql2": "^3.14.1",
|
|
51
|
-
"pg": "^8.16.
|
|
51
|
+
"pg": "^8.16.3",
|
|
52
52
|
"postgres": "^3.4.7"
|
|
53
53
|
}
|
|
54
54
|
}
|