Skip to content

Commit

Permalink
fix(db): isolate AstroDbError from core utils (#10646)
Browse files Browse the repository at this point in the history
* fix(db): isolate AstroDbError from core utils

* add changeset
  • Loading branch information
lilnasy authored Apr 2, 2024
1 parent 51112ab commit 713f99e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-news-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Fixes an issue astro:db could not be used on serverless platforms.
2 changes: 1 addition & 1 deletion packages/db/src/core/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { blue, yellow } from 'kleur/colors';
import { loadEnv } from 'vite';
import parseArgs from 'yargs-parser';
import { SEED_DEV_FILE_NAME } from '../../runtime/queries.js';
import { AstroDbError } from '../../utils.js';
import { AstroDbError } from '../../runtime/utils.js';
import { CONFIG_FILE_NAMES, DB_PATH } from '../consts.js';
import { resolveDbConfig } from '../load-file.js';
import { type ManagedAppToken, getManagedAppTokenOrExit } from '../tokens.js';
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/runtime/db-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type { LibSQLDatabase } from 'drizzle-orm/libsql';
import { drizzle as drizzleLibsql } from 'drizzle-orm/libsql';
import { type SqliteRemoteDatabase, drizzle as drizzleProxy } from 'drizzle-orm/sqlite-proxy';
import { z } from 'zod';
import { AstroDbError } from '../utils.js';
import { safeFetch } from './utils.js';
import { AstroDbError, safeFetch } from './utils.js';

const isWebContainer = !!process.versions?.webcontainer;

Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/runtime/seed-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type SQL, sql } from 'drizzle-orm';
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core';
import { type DBTables } from '../core/types.js';
import { AstroDbError } from '../utils.js';
import { AstroDbError } from './utils.js';
import { SEED_DEFAULT_EXPORT_ERROR } from './errors.js';
import { getCreateIndexQueries, getCreateTableQuery } from './queries.js';

Expand Down
6 changes: 6 additions & 0 deletions packages/db/src/runtime/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AstroError } from 'astro/errors';

/**
* Small wrapper around fetch that throws an error if the response is not OK. Allows for custom error handling as well through the onNotOK callback.
*/
Expand All @@ -16,3 +18,7 @@ export async function safeFetch(

return response;
}

export class AstroDbError extends AstroError {
name = 'Astro DB Error';
}
6 changes: 0 additions & 6 deletions packages/db/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
import { AstroError } from 'astro/errors';

export { defineDbIntegration } from './core/utils.js';
export { asDrizzleTable } from './runtime/index.js';

export class AstroDbError extends AstroError {
name = 'Astro DB Error';
}

0 comments on commit 713f99e

Please sign in to comment.