diff options
author | 2024-03-07 13:38:43 -0500 | |
---|---|---|
committer | 2024-03-07 13:38:43 -0500 | |
commit | 06fe94e29de97290cb41c4f862ab88f48cda3d4a (patch) | |
tree | 2081ae73b962114cca2fa0a4594d6147c6617ae1 /packages/db/src/runtime/index.ts | |
parent | 123f6f855129d2272f8619c685a848ee40fe9535 (diff) | |
download | astro-06fe94e29de97290cb41c4f862ab88f48cda3d4a.tar.gz astro-06fe94e29de97290cb41c4f862ab88f48cda3d4a.tar.zst astro-06fe94e29de97290cb41c4f862ab88f48cda3d4a.zip |
Add `--remote` flag for remote connection (#10352)
* feat: check for --remote
* chore: remove bad ticketing example cols
* fix: get seed file working with build
* Revert "fix: get seed file working with build"
This reverts commit 92830a106164b0997c820a3e0bf2a582018084a0.
* fix: seed from build instead of runtime
* refactor: move recreateTables out of runtime
* Revert "refactor: move recreateTables out of runtime"
This reverts commit d01a802ad7915fabc4c4ac35b2d907eae0538d95.
* fix: in-memory db for test fixture
* chore: changeset
* refactor: generate random db name instead
* refactor: use yargs-parser for flag
* chore: remove in-memory db logi
* refactor: rename random id flag for clarity
* feat: support --remote in dev
* feat: support --remote on shell
* refactor: inline db client
* feat: support --remote on db execute
* chore: stray console log
* chore: remove recreateTables from runtime
* chore: update seeding for new signature
* chore: remove unused error imports
Diffstat (limited to 'packages/db/src/runtime/index.ts')
-rw-r--r-- | packages/db/src/runtime/index.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/packages/db/src/runtime/index.ts b/packages/db/src/runtime/index.ts index 501ae7a22..22958c7da 100644 --- a/packages/db/src/runtime/index.ts +++ b/packages/db/src/runtime/index.ts @@ -11,12 +11,36 @@ import { } from 'drizzle-orm/sqlite-core'; import { type DBColumn, type DBTable } from '../core/types.js'; import { type SerializedSQL, isSerializedSQL } from './types.js'; +import { SEED_DEFAULT_EXPORT_ERROR, SEED_ERROR } from '../core/errors.js'; +import { LibsqlError } from '@libsql/client'; export { sql }; export type SqliteDB = LibSQLDatabase; export type { Table } from './types.js'; export { createRemoteDatabaseClient, createLocalDatabaseClient } from './db-client.js'; -export { seedLocal } from './queries.js'; + +export async function seedLocal({ + // Glob all potential seed files to catch renames and deletions. + fileGlob, +}: { + fileGlob: Record<string, { default?: () => Promise<void> }>; +}) { + const seedFilePath = Object.keys(fileGlob)[0]; + if (!seedFilePath) return; + const mod = fileGlob[seedFilePath]; + + if (!mod.default) { + throw new Error(SEED_DEFAULT_EXPORT_ERROR(seedFilePath)); + } + try { + await mod.default(); + } catch (e) { + if (e instanceof LibsqlError) { + throw new Error(SEED_ERROR(e.message)); + } + throw e; + } +} export function hasPrimaryKey(column: DBColumn) { return 'primaryKey' in column.schema && !!column.schema.primaryKey; |