@astrojs/db 0.1.12 → 0.1.14
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/internal.d.ts +1 -1
- package/dist/internal.js +2 -1
- package/dist/typegen.js +2 -1
- package/dist/utils-runtime.d.ts +1 -0
- package/dist/utils-runtime.js +12 -1
- package/dist/vite-plugin-db.js +4 -11
- package/package.json +1 -1
package/dist/internal.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type BooleanField, type DBCollection, type DBCollections, type DBField,
|
|
|
3
3
|
import { type LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
4
4
|
import { type ColumnDataType } from 'drizzle-orm';
|
|
5
5
|
import type { AstroIntegrationLogger } from 'astro';
|
|
6
|
-
export { createRemoteDatabaseClient } from './utils-runtime.js';
|
|
6
|
+
export { createRemoteDatabaseClient, findLocalDatabase } from './utils-runtime.js';
|
|
7
7
|
export type SqliteDB = SqliteRemoteDatabase;
|
|
8
8
|
export type { Table } from './types.js';
|
|
9
9
|
export declare function hasPrimaryKey(field: DBField): boolean;
|
package/dist/internal.js
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
text
|
|
16
16
|
} from "drizzle-orm/sqlite-core";
|
|
17
17
|
import { z } from "zod";
|
|
18
|
-
import { createRemoteDatabaseClient } from "./utils-runtime.js";
|
|
18
|
+
import { createRemoteDatabaseClient, findLocalDatabase } from "./utils-runtime.js";
|
|
19
19
|
const sqlite = new SQLiteAsyncDialect();
|
|
20
20
|
function hasPrimaryKey(field) {
|
|
21
21
|
return "primaryKey" in field && !!field.primaryKey;
|
|
@@ -271,6 +271,7 @@ export {
|
|
|
271
271
|
collectionToTable,
|
|
272
272
|
createLocalDatabaseClient,
|
|
273
273
|
createRemoteDatabaseClient,
|
|
274
|
+
findLocalDatabase,
|
|
274
275
|
getCreateTableQuery,
|
|
275
276
|
getModifiers,
|
|
276
277
|
hasDefault,
|
package/dist/typegen.js
CHANGED
|
@@ -5,7 +5,8 @@ async function typegen({ collections, root }) {
|
|
|
5
5
|
const content = `// This file is generated by \`studio sync\`
|
|
6
6
|
declare module 'astro:db' {
|
|
7
7
|
export const db: import(${INTERNAL_MOD_IMPORT}).SqliteDB;
|
|
8
|
-
export
|
|
8
|
+
export const dbUrl: string;
|
|
9
|
+
export * from ${DRIZZLE_MOD_IMPORT};
|
|
9
10
|
|
|
10
11
|
${Object.entries(collections).map(([name, collection]) => generateTableType(name, collection)).join("\n")}
|
|
11
12
|
}
|
package/dist/utils-runtime.d.ts
CHANGED
package/dist/utils-runtime.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { drizzle } from "drizzle-orm/sqlite-proxy";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { DB_PATH } from "./consts.js";
|
|
4
|
+
function findLocalDatabase(localDbURL) {
|
|
5
|
+
let dbURL = void 0;
|
|
6
|
+
if (import.meta.env.VERCEL) {
|
|
7
|
+
dbURL = new URL(DB_PATH, "file://" + process.cwd() + "/vercel/path0/");
|
|
8
|
+
} else {
|
|
9
|
+
dbURL = new URL(localDbURL);
|
|
10
|
+
}
|
|
11
|
+
return dbURL.toString();
|
|
12
|
+
}
|
|
3
13
|
function createRemoteDatabaseClient(appToken, remoteDbURL) {
|
|
4
14
|
const url = new URL("./db/query/", remoteDbURL);
|
|
5
15
|
const db = drizzle(async (sql, parameters, method) => {
|
|
@@ -48,5 +58,6 @@ Full error: Unexpected JSON response. ${e instanceof Error ? e.message : String(
|
|
|
48
58
|
return db;
|
|
49
59
|
}
|
|
50
60
|
export {
|
|
51
|
-
createRemoteDatabaseClient
|
|
61
|
+
createRemoteDatabaseClient,
|
|
62
|
+
findLocalDatabase
|
|
52
63
|
};
|
package/dist/vite-plugin-db.js
CHANGED
|
@@ -35,23 +35,16 @@ function getVirtualModContents({
|
|
|
35
35
|
dbUrl
|
|
36
36
|
}) {
|
|
37
37
|
return `
|
|
38
|
-
import { collectionToTable, createLocalDatabaseClient } from ${INTERNAL_MOD_IMPORT};
|
|
39
|
-
|
|
38
|
+
import { collectionToTable, createLocalDatabaseClient, findLocalDatabase } from ${INTERNAL_MOD_IMPORT};
|
|
39
|
+
|
|
40
|
+
export const dbUrl = findLocalDatabase(${JSON.stringify(dbUrl)});
|
|
40
41
|
|
|
41
42
|
const params = ${JSON.stringify({
|
|
42
43
|
collections,
|
|
43
44
|
seeding: false
|
|
44
45
|
})};
|
|
45
|
-
|
|
46
|
-
export let dbUrl = ${JSON.stringify(dbUrl)};
|
|
47
|
-
|
|
48
|
-
// This is gross
|
|
49
|
-
if(import.meta.env.VERCEL) {
|
|
50
|
-
dbUrl = new URL(${JSON.stringify(DB_PATH)}, 'file://' + process.cwd() + '/vercel/path0/');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
46
|
params.dbUrl = dbUrl;
|
|
54
|
-
|
|
47
|
+
|
|
55
48
|
export const db = await createLocalDatabaseClient(params);
|
|
56
49
|
|
|
57
50
|
export * from ${DRIZZLE_MOD_IMPORT};
|