@astrojs/db 0.8.7 → 0.9.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.
@@ -1,5 +1,6 @@
1
1
  import type { ColumnsConfig, DBConfigInput, TableConfig } from '../core/types.js';
2
- export type { LibSQLDatabase } from 'drizzle-orm/libsql';
2
+ import type { LibSQLDatabase } from 'drizzle-orm/libsql';
3
+ export type Database = Omit<LibSQLDatabase, 'transaction'>;
3
4
  export declare const column: {
4
5
  number: <T extends ({
5
6
  name?: string | undefined;
@@ -148,4 +149,4 @@ export declare function defineDb(userConfig: DBConfigInput): {
148
149
  export declare const NOW: import("drizzle-orm").SQL<unknown>;
149
150
  export declare const TRUE: import("drizzle-orm").SQL<unknown>;
150
151
  export declare const FALSE: import("drizzle-orm").SQL<unknown>;
151
- export { sql, eq, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, exists, notExists, between, notBetween, like, notIlike, not, asc, desc, and, or, } from 'drizzle-orm';
152
+ export { sql, eq, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, exists, notExists, between, notBetween, like, notIlike, not, asc, desc, and, or, count, countDistinct, avg, avgDistinct, sum, sumDistinct, max, min, } from 'drizzle-orm';
@@ -7,7 +7,6 @@ import { hasPrimaryKey } from "../../runtime/index.js";
7
7
  import {
8
8
  getCreateIndexQueries,
9
9
  getCreateTableQuery,
10
- getDropTableIfExistsQuery,
11
10
  getModifiers,
12
11
  getReferencesConfig,
13
12
  hasDefault,
@@ -57,7 +56,7 @@ async function getMigrationQueries({
57
56
  const addedColumns = getAdded(oldCollection.columns, newCollection.columns);
58
57
  const droppedColumns = getDropped(oldCollection.columns, newCollection.columns);
59
58
  const notDeprecatedDroppedColumns = Object.fromEntries(
60
- Object.entries(droppedColumns).filter(([key, col]) => !col.schema.deprecated)
59
+ Object.entries(droppedColumns).filter(([, col]) => !col.schema.deprecated)
61
60
  );
62
61
  if (!isEmpty(addedColumns) && !isEmpty(notDeprecatedDroppedColumns)) {
63
62
  throw new Error(
@@ -27,7 +27,7 @@ function printHelp({
27
27
  message.push(
28
28
  linebreak(),
29
29
  ` ${bgGreen(black(` ${commandName} `))} ${green(
30
- `v${"0.8.7"}`
30
+ `v${"0.9.0"}`
31
31
  )} ${headline}`
32
32
  );
33
33
  }
@@ -19,7 +19,7 @@ ${Object.entries(tables).map(([name, collection]) => generateTableType(name, col
19
19
  await writeFile(new URL(DB_TYPES_FILE, dotAstroDir), content);
20
20
  }
21
21
  function generateTableType(name, collection) {
22
- const sanitizedColumnsList = Object.entries(collection.columns).filter(([key, val]) => !val.schema.deprecated);
22
+ const sanitizedColumnsList = Object.entries(collection.columns).filter(([, val]) => !val.schema.deprecated);
23
23
  const sanitizedColumns = Object.fromEntries(sanitizedColumnsList);
24
24
  let tableType = ` export const ${name}: import(${RUNTIME_IMPORT}).Table<
25
25
  ${JSON.stringify(name)},
@@ -94,10 +94,7 @@ function getStudioVirtualModContents({
94
94
  return `
95
95
  import {asDrizzleTable, createRemoteDatabaseClient} from ${RUNTIME_IMPORT};
96
96
 
97
- export const db = await createRemoteDatabaseClient(process.env.ASTRO_STUDIO_APP_TOKEN ?? ${JSON.stringify(
98
- appToken
99
- // Respect runtime env for user overrides in SSR
100
- )}, import.meta.env.ASTRO_STUDIO_REMOTE_DB_URL ?? ${JSON.stringify(getRemoteDatabaseUrl())});
97
+ export const db = await createRemoteDatabaseClient(process.env.ASTRO_STUDIO_APP_TOKEN);
101
98
 
102
99
  export * from ${RUNTIME_CONFIG_IMPORT};
103
100
 
@@ -50,7 +50,6 @@ class ManagedRemoteAppToken {
50
50
  throw new Error(`Failed to create token: ${res.status} ${res.statusText}`);
51
51
  }
52
52
  );
53
- await new Promise((resolve) => setTimeout(resolve, 2e3));
54
53
  spinner.succeed(green("Connected to remote database."));
55
54
  const { token, ttl } = await response.json();
56
55
  return { token, ttl };
@@ -56,7 +56,15 @@ import {
56
56
  asc,
57
57
  desc,
58
58
  and,
59
- or
59
+ or,
60
+ count,
61
+ countDistinct,
62
+ avg,
63
+ avgDistinct,
64
+ sum,
65
+ sumDistinct,
66
+ max,
67
+ min
60
68
  } from "drizzle-orm";
61
69
  export {
62
70
  FALSE,
@@ -64,8 +72,12 @@ export {
64
72
  TRUE,
65
73
  and,
66
74
  asc,
75
+ avg,
76
+ avgDistinct,
67
77
  between,
68
78
  column,
79
+ count,
80
+ countDistinct,
69
81
  defineDb,
70
82
  defineTable,
71
83
  desc,
@@ -79,6 +91,8 @@ export {
79
91
  like,
80
92
  lt,
81
93
  lte,
94
+ max,
95
+ min,
82
96
  ne,
83
97
  not,
84
98
  notBetween,
@@ -86,5 +100,7 @@ export {
86
100
  notIlike,
87
101
  notInArray,
88
102
  or,
89
- sql
103
+ sql,
104
+ sum,
105
+ sumDistinct
90
106
  };
@@ -1,5 +1,6 @@
1
1
  import type { LibSQLDatabase } from 'drizzle-orm/libsql';
2
+ import { type SqliteRemoteDatabase } from 'drizzle-orm/sqlite-proxy';
2
3
  export declare function createLocalDatabaseClient({ dbUrl }: {
3
4
  dbUrl: string;
4
5
  }): LibSQLDatabase;
5
- export declare function createRemoteDatabaseClient(appToken: string, remoteDbURL: string): import("drizzle-orm/sqlite-proxy").SqliteRemoteDatabase<Record<string, never>>;
6
+ export declare function createRemoteDatabaseClient(appToken: string, remoteDbURL: string): SqliteRemoteDatabase<Record<string, never>>;
@@ -4,10 +4,20 @@ import { drizzle as drizzleProxy } from "drizzle-orm/sqlite-proxy";
4
4
  import { z } from "zod";
5
5
  import { safeFetch } from "./utils.js";
6
6
  const isWebContainer = !!process.versions?.webcontainer;
7
+ function applyTransactionNotSupported(db) {
8
+ Object.assign(db, {
9
+ transaction() {
10
+ throw new Error(
11
+ "`db.transaction()` is not currently supported. We recommend `db.batch()` for automatic error rollbacks across multiple queries."
12
+ );
13
+ }
14
+ });
15
+ }
7
16
  function createLocalDatabaseClient({ dbUrl }) {
8
17
  const url = isWebContainer ? "file:content.db" : dbUrl;
9
18
  const client = createClient({ url });
10
19
  const db = drizzleLibsql(client);
20
+ applyTransactionNotSupported(db);
11
21
  return db;
12
22
  }
13
23
  const remoteResultSchema = z.object({
@@ -113,6 +123,7 @@ Full error: Unexpected JSON response. ${e instanceof Error ? e.message : String(
113
123
  return results;
114
124
  }
115
125
  );
126
+ applyTransactionNotSupported(db);
116
127
  return db;
117
128
  }
118
129
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/db",
3
- "version": "0.8.7",
3
+ "version": "0.9.0",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -58,7 +58,8 @@
58
58
  "@libsql/client": "^0.5.5",
59
59
  "async-listen": "^3.0.1",
60
60
  "deep-diff": "^1.0.2",
61
- "drizzle-orm": "^0.29.5",
61
+ "drizzle-orm": "^0.30.2",
62
+ "github-slugger": "^2.0.0",
62
63
  "kleur": "^4.1.5",
63
64
  "nanoid": "^5.0.1",
64
65
  "open": "^10.0.3",
@@ -80,7 +81,7 @@
80
81
  "mocha": "^10.2.0",
81
82
  "typescript": "^5.2.2",
82
83
  "vite": "^5.1.4",
83
- "astro": "4.5.6",
84
+ "astro": "4.5.7",
84
85
  "astro-scripts": "0.0.14"
85
86
  },
86
87
  "scripts": {
package/virtual.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare module 'astro:db' {
2
2
  type RuntimeConfig = typeof import('./dist/_internal/runtime/config.js');
3
3
 
4
- export const db: import('./dist/_internal/runtime/config.js').LibSQLDatabase;
4
+ export const db: import('./dist/_internal/runtime/config.js').Database;
5
5
  export const dbUrl: string;
6
6
 
7
7
  export const sql: RuntimeConfig['sql'];
@@ -33,4 +33,12 @@ declare module 'astro:db' {
33
33
  export const desc: RuntimeConfig['desc'];
34
34
  export const and: RuntimeConfig['and'];
35
35
  export const or: RuntimeConfig['or'];
36
+ export const count: RuntimeConfig['count'];
37
+ export const countDistinct: RuntimeConfig['countDistinct'];
38
+ export const avg: RuntimeConfig['avg'];
39
+ export const avgDistinct: RuntimeConfig['avgDistinct'];
40
+ export const sum: RuntimeConfig['sum'];
41
+ export const sumDistinct: RuntimeConfig['sumDistinct'];
42
+ export const max: RuntimeConfig['max'];
43
+ export const min: RuntimeConfig['min'];
36
44
  }