@astrojs/db 0.6.4 → 0.7.0
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/core/cli/commands/execute/index.js +30 -8
- package/dist/core/cli/commands/push/index.js +2 -2
- package/dist/core/cli/commands/shell/index.d.ts +1 -1
- package/dist/core/cli/commands/shell/index.js +23 -7
- package/dist/core/cli/index.js +2 -4
- package/dist/core/cli/migration-queries.js +3 -2
- package/dist/core/consts.d.ts +2 -2
- package/dist/core/consts.js +4 -3
- package/dist/core/errors.d.ts +3 -0
- package/dist/core/errors.js +19 -2
- package/dist/core/integration/index.js +16 -11
- package/dist/core/integration/typegen.js +2 -2
- package/dist/core/integration/vite-plugin-db.d.ts +6 -1
- package/dist/core/integration/vite-plugin-db.js +63 -36
- package/dist/core/load-file.d.ts +226 -4
- package/dist/core/load-file.js +73 -5
- package/dist/core/types.d.ts +12 -5
- package/dist/core/utils.d.ts +3 -1
- package/dist/core/utils.js +4 -0
- package/dist/runtime/config.d.ts +3 -2
- package/dist/runtime/config.js +48 -3
- package/dist/runtime/db-client.js +90 -40
- package/dist/runtime/index.d.ts +8 -1
- package/dist/runtime/index.js +32 -1
- package/dist/runtime/queries.d.ts +1 -11
- package/dist/runtime/queries.js +3 -40
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +3 -1
- package/package.json +4 -10
- package/virtual.d.ts +9 -0
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import type { BooleanColumn, ColumnType, DBColumn, DBTable,
|
|
2
|
-
import { type SqliteDB } from './index.js';
|
|
1
|
+
import type { BooleanColumn, ColumnType, DBColumn, DBTable, DateColumn, JsonColumn, NumberColumn, TextColumn } from '../core/types.js';
|
|
3
2
|
export declare const SEED_DEV_FILE_NAME: string[];
|
|
4
|
-
export declare function seedLocal({ db, tables, fileGlob, }: {
|
|
5
|
-
db: SqliteDB;
|
|
6
|
-
tables: DBTables;
|
|
7
|
-
fileGlob: Record<string, () => Promise<void>>;
|
|
8
|
-
}): Promise<void>;
|
|
9
|
-
export declare function recreateTables({ db, tables }: {
|
|
10
|
-
db: SqliteDB;
|
|
11
|
-
tables: DBTables;
|
|
12
|
-
}): Promise<void>;
|
|
13
3
|
export declare function getDropTableIfExistsQuery(tableName: string): string;
|
|
14
4
|
export declare function getCreateTableQuery(tableName: string, table: DBTable): string;
|
|
15
5
|
export declare function getCreateIndexQueries(tableName: string, table: Pick<DBTable, 'indexes'>): string[];
|
package/dist/runtime/queries.js
CHANGED
|
@@ -1,51 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { sql } from "drizzle-orm";
|
|
1
|
+
import {} from "drizzle-orm";
|
|
3
2
|
import { SQLiteAsyncDialect } from "drizzle-orm/sqlite-core";
|
|
4
3
|
import { bold } from "kleur/colors";
|
|
5
4
|
import {
|
|
6
5
|
FOREIGN_KEY_DNE_ERROR,
|
|
7
6
|
FOREIGN_KEY_REFERENCES_EMPTY_ERROR,
|
|
8
7
|
FOREIGN_KEY_REFERENCES_LENGTH_ERROR,
|
|
9
|
-
REFERENCE_DNE_ERROR
|
|
10
|
-
SEED_ERROR
|
|
8
|
+
REFERENCE_DNE_ERROR
|
|
11
9
|
} from "../core/errors.js";
|
|
12
10
|
import { hasPrimaryKey } from "./index.js";
|
|
13
11
|
import { isSerializedSQL } from "./types.js";
|
|
14
12
|
const sqlite = new SQLiteAsyncDialect();
|
|
15
13
|
const SEED_DEV_FILE_NAME = ["seed.ts", "seed.js", "seed.mjs", "seed.mts"];
|
|
16
|
-
async function seedLocal({
|
|
17
|
-
db,
|
|
18
|
-
tables,
|
|
19
|
-
// Glob all potential seed files to catch renames and deletions.
|
|
20
|
-
fileGlob
|
|
21
|
-
}) {
|
|
22
|
-
await recreateTables({ db, tables });
|
|
23
|
-
for (const fileName of SEED_DEV_FILE_NAME) {
|
|
24
|
-
const key = Object.keys(fileGlob).find((f) => f.endsWith(fileName));
|
|
25
|
-
if (key) {
|
|
26
|
-
await fileGlob[key]().catch((e) => {
|
|
27
|
-
if (e instanceof LibsqlError) {
|
|
28
|
-
throw new Error(SEED_ERROR(e.message));
|
|
29
|
-
}
|
|
30
|
-
throw e;
|
|
31
|
-
});
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function recreateTables({ db, tables }) {
|
|
37
|
-
const setupQueries = [];
|
|
38
|
-
for (const [name, table] of Object.entries(tables)) {
|
|
39
|
-
const dropQuery = sql.raw(`DROP TABLE IF EXISTS ${sqlite.escapeName(name)}`);
|
|
40
|
-
const createQuery = sql.raw(getCreateTableQuery(name, table));
|
|
41
|
-
const indexQueries = getCreateIndexQueries(name, table);
|
|
42
|
-
setupQueries.push(dropQuery, createQuery, ...indexQueries.map((s) => sql.raw(s)));
|
|
43
|
-
}
|
|
44
|
-
await db.batch([
|
|
45
|
-
db.run(sql`pragma defer_foreign_keys=true;`),
|
|
46
|
-
...setupQueries.map((q) => db.run(q))
|
|
47
|
-
]);
|
|
48
|
-
}
|
|
49
14
|
function getDropTableIfExistsQuery(tableName) {
|
|
50
15
|
return `DROP TABLE IF EXISTS ${sqlite.escapeName(tableName)}`;
|
|
51
16
|
}
|
|
@@ -200,7 +165,5 @@ export {
|
|
|
200
165
|
getModifiers,
|
|
201
166
|
getReferencesConfig,
|
|
202
167
|
hasDefault,
|
|
203
|
-
|
|
204
|
-
schemaTypeToSqlType,
|
|
205
|
-
seedLocal
|
|
168
|
+
schemaTypeToSqlType
|
|
206
169
|
};
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,10 +20,6 @@
|
|
|
20
20
|
"types": "./dist/runtime/index.d.ts",
|
|
21
21
|
"import": "./dist/runtime/index.js"
|
|
22
22
|
},
|
|
23
|
-
"./runtime/drizzle": {
|
|
24
|
-
"types": "./dist/runtime/drizzle.d.ts",
|
|
25
|
-
"import": "./dist/runtime/drizzle.js"
|
|
26
|
-
},
|
|
27
23
|
"./runtime/config": {
|
|
28
24
|
"types": "./dist/runtime/config.d.ts",
|
|
29
25
|
"import": "./dist/runtime/config.js"
|
|
@@ -41,9 +37,6 @@
|
|
|
41
37
|
"runtime": [
|
|
42
38
|
"./dist/runtime/index.d.ts"
|
|
43
39
|
],
|
|
44
|
-
"runtime/drizzle": [
|
|
45
|
-
"./dist/runtime/drizzle.d.ts"
|
|
46
|
-
],
|
|
47
40
|
"runtime/config": [
|
|
48
41
|
"./dist/runtime/config.d.ts"
|
|
49
42
|
]
|
|
@@ -51,6 +44,7 @@
|
|
|
51
44
|
},
|
|
52
45
|
"files": [
|
|
53
46
|
"index.d.ts",
|
|
47
|
+
"virtual.d.ts",
|
|
54
48
|
"dist"
|
|
55
49
|
],
|
|
56
50
|
"keywords": [
|
|
@@ -61,7 +55,7 @@
|
|
|
61
55
|
"@libsql/client": "^0.4.3",
|
|
62
56
|
"async-listen": "^3.0.1",
|
|
63
57
|
"deep-diff": "^1.0.2",
|
|
64
|
-
"drizzle-orm": "^0.
|
|
58
|
+
"drizzle-orm": "^0.29.5",
|
|
65
59
|
"kleur": "^4.1.5",
|
|
66
60
|
"nanoid": "^5.0.1",
|
|
67
61
|
"open": "^10.0.3",
|
|
@@ -83,7 +77,7 @@
|
|
|
83
77
|
"mocha": "^10.2.0",
|
|
84
78
|
"typescript": "^5.2.2",
|
|
85
79
|
"vite": "^5.1.4",
|
|
86
|
-
"astro": "4.4.
|
|
80
|
+
"astro": "4.4.15",
|
|
87
81
|
"astro-scripts": "0.0.14"
|
|
88
82
|
},
|
|
89
83
|
"scripts": {
|
package/virtual.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare module 'astro:db' {
|
|
2
|
+
export const sql: typeof import('./dist/runtime/config.js').sql;
|
|
3
|
+
export const NOW: typeof import('./dist/runtime/config.js').NOW;
|
|
4
|
+
export const TRUE: typeof import('./dist/runtime/config.js').TRUE;
|
|
5
|
+
export const FALSE: typeof import('./dist/runtime/config.js').FALSE;
|
|
6
|
+
export const column: typeof import('./dist/runtime/config.js').column;
|
|
7
|
+
export const defineDb: typeof import('./dist/runtime/config.js').defineDb;
|
|
8
|
+
export const defineTable: typeof import('./dist/runtime/config.js').defineTable;
|
|
9
|
+
}
|