@coreframe/db 0.1.1 → 0.1.3
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/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/local-postgres.d.ts +2 -0
- package/dist/local-postgres.js +1 -1
- package/dist/migrate.d.ts +6 -0
- package/dist/migrate.js +1 -1
- package/dist/project.d.ts +8 -1
- package/dist/project.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { HELD_MIGRATIONS_FOLDER, MIGRATIONS_FOLDER, NOW, SEED_EMAILS, SEED_IDS,
|
|
|
5
5
|
import { runDrizzleKitCommand } from "./drizzle-kit.js";
|
|
6
6
|
import { ensureLocalDb } from "./ensure.js";
|
|
7
7
|
import { formatDbErrorMessage } from "./error.js";
|
|
8
|
-
import { CreateProjectDatabaseOptions, createProjectDeployDatabase, createProjectPostgresDrizzleDatabase } from "./project.js";
|
|
8
|
+
import { CreateProjectDatabaseOptions, createProjectDeployDatabase, createProjectPostgresDrizzleDatabase, createProjectSqliteDrizzleDatabase } from "./project.js";
|
|
9
9
|
import { LOCAL_POSTGRES_ENV_FLAG, LocalPostgresDb, ProjectPostgresAlreadyRunningError, ProjectPostgresSidecar, StartProjectPostgresOptions, StartTemporaryProjectPostgresOptions, createLocalPostgresDb, createLocalPostgresEnv, getLocalPostgresConnectionString, startProjectPostgres, startTemporaryProjectPostgres, stopProjectPostgres } from "./local-postgres.js";
|
|
10
10
|
import { heldMigrationInsertQuery, heldMigrationSelectQuery, migrateHeldMigrations, validateHeldMigrationHeader } from "./migrate-held.js";
|
|
11
11
|
import { migrateLocalDb } from "./migrate.js";
|
|
@@ -16,4 +16,4 @@ import { checkSchemaPush } from "./schema-check.js";
|
|
|
16
16
|
import { SchemaPushModule, SchemaPushPlan, inferSchemaDialect, planLocalSchemaPush } from "./schema-push.js";
|
|
17
17
|
import { runProjectSeed, seedLocalDb } from "./seed.js";
|
|
18
18
|
import { setupLocalDb } from "./setup.js";
|
|
19
|
-
export { CreateDatabaseAdapterOptions, CreateProjectDatabaseOptions, DatabaseClient, DatabaseDialect, DrizzleExecutor, HELD_MIGRATIONS_FOLDER, LOCAL_POSTGRES_ENV_FLAG, LocalPostgresDb, MIGRATIONS_FOLDER, MigrationFile, MigrationRisk, MigrationScanResult, NOW, ProjectPostgresAlreadyRunningError, ProjectPostgresSidecar, QueryResult, SEED_EMAILS, SEED_IDS, SchemaPushModule, SchemaPushPlan, SeedDatabase, SeedProfile, SeedQuery, StartProjectPostgresOptions, StartTemporaryProjectPostgresOptions, appliedMigrationsQuery, applySeed, checkDeployMigrations, checkSchemaPush, collectDeployMigrationFiles, collectHeldMigrationFiles, createDatabaseAdapter, createLocalPostgresDb, createLocalPostgresEnv, createProjectDeployDatabase, createProjectPostgresDrizzleDatabase, ensureLocalDb, filterPendingMigrations, formatDbErrorMessage, formatMigrationList, formatMigrationScanFailures, generatedUserId, getLocalPostgresConnectionString, getSeedProfile, heldMigrationInsertQuery, heldMigrationSelectQuery, inferSchemaDialect, migrateHeldMigrations, migrateLocalDb, normalizeQueryResult, planLocalSchemaPush, readAppliedMigrationNames, resetLocalDb, runDrizzleKitCommand, runProjectSeed, scanDeployMigrationFiles, scanMigrationSql, seedLocalDb, setupLocalDb, startProjectPostgres, startTemporaryProjectPostgres, stopProjectPostgres, validateHeldMigrationHeader };
|
|
19
|
+
export { CreateDatabaseAdapterOptions, CreateProjectDatabaseOptions, DatabaseClient, DatabaseDialect, DrizzleExecutor, HELD_MIGRATIONS_FOLDER, LOCAL_POSTGRES_ENV_FLAG, LocalPostgresDb, MIGRATIONS_FOLDER, MigrationFile, MigrationRisk, MigrationScanResult, NOW, ProjectPostgresAlreadyRunningError, ProjectPostgresSidecar, QueryResult, SEED_EMAILS, SEED_IDS, SchemaPushModule, SchemaPushPlan, SeedDatabase, SeedProfile, SeedQuery, StartProjectPostgresOptions, StartTemporaryProjectPostgresOptions, appliedMigrationsQuery, applySeed, checkDeployMigrations, checkSchemaPush, collectDeployMigrationFiles, collectHeldMigrationFiles, createDatabaseAdapter, createLocalPostgresDb, createLocalPostgresEnv, createProjectDeployDatabase, createProjectPostgresDrizzleDatabase, createProjectSqliteDrizzleDatabase, ensureLocalDb, filterPendingMigrations, formatDbErrorMessage, formatMigrationList, formatMigrationScanFailures, generatedUserId, getLocalPostgresConnectionString, getSeedProfile, heldMigrationInsertQuery, heldMigrationSelectQuery, inferSchemaDialect, migrateHeldMigrations, migrateLocalDb, normalizeQueryResult, planLocalSchemaPush, readAppliedMigrationNames, resetLocalDb, runDrizzleKitCommand, runProjectSeed, scanDeployMigrationFiles, scanMigrationSql, seedLocalDb, setupLocalDb, startProjectPostgres, startTemporaryProjectPostgres, stopProjectPostgres, validateHeldMigrationHeader };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{applySeed as e}from"./apply-seed.js";import{HELD_MIGRATIONS_FOLDER as t,MIGRATIONS_FOLDER as n,NOW as r,SEED_EMAILS as i,SEED_IDS as a,generatedUserId as o,getSeedProfile as s}from"./config.js";import{collectDeployMigrationFiles as c,collectHeldMigrationFiles as l,formatMigrationList as u,formatMigrationScanFailures as d,scanDeployMigrationFiles as f,scanMigrationSql as p}from"./migrations.js";import{checkDeployMigrations as m}from"./check-migrations.js";import{createDatabaseAdapter as h,normalizeQueryResult as g}from"./client.js";import{createProjectDeployDatabase as _,createProjectPostgresDrizzleDatabase as v}from"./project.js";import{LOCAL_POSTGRES_ENV_FLAG as
|
|
1
|
+
import{applySeed as e}from"./apply-seed.js";import{HELD_MIGRATIONS_FOLDER as t,MIGRATIONS_FOLDER as n,NOW as r,SEED_EMAILS as i,SEED_IDS as a,generatedUserId as o,getSeedProfile as s}from"./config.js";import{collectDeployMigrationFiles as c,collectHeldMigrationFiles as l,formatMigrationList as u,formatMigrationScanFailures as d,scanDeployMigrationFiles as f,scanMigrationSql as p}from"./migrations.js";import{checkDeployMigrations as m}from"./check-migrations.js";import{createDatabaseAdapter as h,normalizeQueryResult as g}from"./client.js";import{createProjectDeployDatabase as _,createProjectPostgresDrizzleDatabase as v,createProjectSqliteDrizzleDatabase as y}from"./project.js";import{LOCAL_POSTGRES_ENV_FLAG as b,ProjectPostgresAlreadyRunningError as x,createLocalPostgresDb as S,createLocalPostgresEnv as C,getLocalPostgresConnectionString as w,startProjectPostgres as T,startTemporaryProjectPostgres as E,stopProjectPostgres as D}from"./local-postgres.js";import{runDrizzleKitCommand as O}from"./drizzle-kit.js";import{inferSchemaDialect as k,planLocalSchemaPush as A}from"./schema-push.js";import{runProjectSeed as j,seedLocalDb as M}from"./seed.js";import{migrateLocalDb as N}from"./migrate.js";import{resetLocalDb as P}from"./reset.js";import{setupLocalDb as F}from"./setup.js";import{ensureLocalDb as I}from"./ensure.js";import{formatDbErrorMessage as L}from"./error.js";import{heldMigrationInsertQuery as R,heldMigrationSelectQuery as z,migrateHeldMigrations as B,validateHeldMigrationHeader as V}from"./migrate-held.js";import{appliedMigrationsQuery as H,filterPendingMigrations as U,readAppliedMigrationNames as W}from"./pending-migrations.js";import{checkSchemaPush as G}from"./schema-check.js";export{t as HELD_MIGRATIONS_FOLDER,b as LOCAL_POSTGRES_ENV_FLAG,n as MIGRATIONS_FOLDER,r as NOW,x as ProjectPostgresAlreadyRunningError,i as SEED_EMAILS,a as SEED_IDS,H as appliedMigrationsQuery,e as applySeed,m as checkDeployMigrations,G as checkSchemaPush,c as collectDeployMigrationFiles,l as collectHeldMigrationFiles,h as createDatabaseAdapter,S as createLocalPostgresDb,C as createLocalPostgresEnv,_ as createProjectDeployDatabase,v as createProjectPostgresDrizzleDatabase,y as createProjectSqliteDrizzleDatabase,I as ensureLocalDb,U as filterPendingMigrations,L as formatDbErrorMessage,u as formatMigrationList,d as formatMigrationScanFailures,o as generatedUserId,w as getLocalPostgresConnectionString,s as getSeedProfile,R as heldMigrationInsertQuery,z as heldMigrationSelectQuery,k as inferSchemaDialect,B as migrateHeldMigrations,N as migrateLocalDb,g as normalizeQueryResult,A as planLocalSchemaPush,W as readAppliedMigrationNames,P as resetLocalDb,O as runDrizzleKitCommand,j as runProjectSeed,f as scanDeployMigrationFiles,p as scanMigrationSql,M as seedLocalDb,F as setupLocalDb,T as startProjectPostgres,E as startTemporaryProjectPostgres,D as stopProjectPostgres,V as validateHeldMigrationHeader};
|
package/dist/local-postgres.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ type LocalPostgresDb = Awaited<ReturnType<typeof createProjectPostgresDrizzleDat
|
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
type LocalPostgresOptions = {
|
|
24
|
+
cwd?: string;
|
|
24
25
|
env?: NodeJS.ProcessEnv;
|
|
25
26
|
};
|
|
26
27
|
type ProjectPostgresSidecar = {
|
|
@@ -60,6 +61,7 @@ declare function startTemporaryProjectPostgres({
|
|
|
60
61
|
}?: StartTemporaryProjectPostgresOptions): Promise<ProjectPostgresSidecar>;
|
|
61
62
|
declare function createLocalPostgresEnv(env: NodeJS.ProcessEnv, postgresEnv: LocalPostgresEnv): NodeJS.ProcessEnv;
|
|
62
63
|
declare function createLocalPostgresDb({
|
|
64
|
+
cwd,
|
|
63
65
|
env
|
|
64
66
|
}?: LocalPostgresOptions): Promise<LocalPostgresDb>;
|
|
65
67
|
declare function getLocalPostgresConnectionString(env?: NodeJS.ProcessEnv): string;
|
package/dist/local-postgres.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fs as e,os as t}from"./environment.js";import{createProjectPostgresDrizzleDatabase as n}from"./project.js";import r from"node:path";import{readProjectConfig as i}from"@coreframe/config";import{connectExistingDevSupervisor as a}from"@coreframe/dev-supervisor";import{startPostgres as o}from"local-postgres";import{PostgresDataDirInUseError as s,stopPostgresDataDir as c}from"local-postgres/core";const l=`COREFRAME_LOCAL_POSTGRES`,u=`coreframe`,d=2e3,f=4e3,p=new Map,m={name:`coreframe`,password:`coreframe`};var h=class extends Error{dataDir;pid;constructor(e,t,n){super(`PostgreSQL is already running for this project (PID ${t}). Stop the other top-level \`coreframe dev\` process before starting another.`,n),this.name=`ProjectPostgresAlreadyRunningError`,this.dataDir=e,this.pid=t}};async function g({config:t,cwd:n=process.cwd(),env:s=process.env,failIfRunning:c=!1,postgresOutput:l,useSupervisorLease:f=!1}={}){if(s.COREFRAME_LOCAL_POSTGRES===`1`)return T(s);let p=t??await i({cwd:n});if((p.database?.dialect??`postgres`)!==`postgres`)return T(s);if(f){if(s.COREFRAME_DEV_SUPERVISOR!==`0`){let e=await a({cwd:n,env:s});if(e)try{let t=await e.acquirePostgres({config:p,env:s});return E(e,t.leaseId,t.env)}catch(t){throw e.close(),t}}return v({config:p,cwd:n,env:s})}let g=r.resolve(n,`.coreframe/postgres`),_=await D(g);if(_){if(c)throw new h(g,_.pid);return T(O(s,g,_))}let y=r.join(g,`postgres.log`);await e.rm(y,{force:!0});let b;try{b=await o({dataDir:g,database:u,postgresOutput:l??{filePath:y},postgres:{strategy:`prefer-local`},stopTimeoutMs:d,superuser:m})}catch(e){throw await k(e,l?void 0:y)}return x(s,b)}async function _({dataDir:e,pid:t}){let n=`${e}\0${t}`,r=p.get(n);if(r){await r;return}let i=C(e,t);p.set(n,i);try{await i}finally{p.get(n)===i&&p.delete(n)}}async function v({config:n,cwd:a=process.cwd(),env:s=process.env}={}){let c=(n??await i({cwd:a})).database?.dialect??`postgres`;if(c!==`postgres`)throw Error(`Temporary schema push checks require PostgreSQL, but this project uses ${c}.`);let l=await e.mkdtemp(r.join(t.tmpdir(),`coreframe-schema-check-`));try{let t=x(s,await o({dataDir:l,database:u,postgresOutput:`ignore`,postgres:{strategy:`prefer-local`},stopTimeoutMs:d,superuser:m}));return{env:t.env,async[Symbol.asyncDispose](){await t[Symbol.asyncDispose](),await e.rm(l,{force:!0,recursive:!0})}}}catch(e){throw await w(l,e),e}}function y(e,t){return{...e,...t,[l]:`1`}}async function b({
|
|
1
|
+
import{fs as e,os as t}from"./environment.js";import{createProjectPostgresDrizzleDatabase as n}from"./project.js";import r from"node:path";import{readProjectConfig as i}from"@coreframe/config";import{connectExistingDevSupervisor as a}from"@coreframe/dev-supervisor";import{startPostgres as o}from"local-postgres";import{PostgresDataDirInUseError as s,stopPostgresDataDir as c}from"local-postgres/core";const l=`COREFRAME_LOCAL_POSTGRES`,u=`coreframe`,d=2e3,f=4e3,p=new Map,m={name:`coreframe`,password:`coreframe`};var h=class extends Error{dataDir;pid;constructor(e,t,n){super(`PostgreSQL is already running for this project (PID ${t}). Stop the other top-level \`coreframe dev\` process before starting another.`,n),this.name=`ProjectPostgresAlreadyRunningError`,this.dataDir=e,this.pid=t}};async function g({config:t,cwd:n=process.cwd(),env:s=process.env,failIfRunning:c=!1,postgresOutput:l,useSupervisorLease:f=!1}={}){if(s.COREFRAME_LOCAL_POSTGRES===`1`)return T(s);let p=t??await i({cwd:n});if((p.database?.dialect??`postgres`)!==`postgres`)return T(s);if(f){if(s.COREFRAME_DEV_SUPERVISOR!==`0`){let e=await a({cwd:n,env:s});if(e)try{let t=await e.acquirePostgres({config:p,env:s});return E(e,t.leaseId,t.env)}catch(t){throw e.close(),t}}return v({config:p,cwd:n,env:s})}let g=r.resolve(n,`.coreframe/postgres`),_=await D(g);if(_){if(c)throw new h(g,_.pid);return T(O(s,g,_))}let y=r.join(g,`postgres.log`);await e.rm(y,{force:!0});let b;try{b=await o({dataDir:g,database:u,postgresOutput:l??{filePath:y},postgres:{strategy:`prefer-local`},stopTimeoutMs:d,superuser:m})}catch(e){throw await k(e,l?void 0:y)}return x(s,b)}async function _({dataDir:e,pid:t}){let n=`${e}\0${t}`,r=p.get(n);if(r){await r;return}let i=C(e,t);p.set(n,i);try{await i}finally{p.get(n)===i&&p.delete(n)}}async function v({config:n,cwd:a=process.cwd(),env:s=process.env}={}){let c=(n??await i({cwd:a})).database?.dialect??`postgres`;if(c!==`postgres`)throw Error(`Temporary schema push checks require PostgreSQL, but this project uses ${c}.`);let l=await e.mkdtemp(r.join(t.tmpdir(),`coreframe-schema-check-`));try{let t=x(s,await o({dataDir:l,database:u,postgresOutput:`ignore`,postgres:{strategy:`prefer-local`},stopTimeoutMs:d,superuser:m}));return{env:t.env,async[Symbol.asyncDispose](){await t[Symbol.asyncDispose](),await e.rm(l,{force:!0,recursive:!0})}}}catch(e){throw await w(l,e),e}}function y(e,t){return{...e,...t,[l]:`1`}}async function b({cwd:e=process.cwd(),env:t=process.env}={}){let r=j(t);return n({cwd:e,env:{...t,DATABASE_URL:r}})}function x(e,t){let n;return{env:y(e,t.env),async[Symbol.asyncDispose](){n??=S(t),await n}}}async function S(e){let t;try{await e[Symbol.asyncDispose]()}catch(e){t=e}if(e.pid===void 0){if(t)throw t;return}try{await c({dataDir:e.dataDir,expectedPid:e.pid,mode:`immediate`,timeoutMs:f})}catch(n){throw t?AggregateError([t,n],`Failed to stop PostgreSQL process ${e.pid}.`):n}}async function C(e,t){try{await c({dataDir:e,expectedPid:t,mode:`fast`,timeoutMs:f})}catch(n){try{await c({dataDir:e,expectedPid:t,mode:`immediate`,timeoutMs:f})}catch(e){throw AggregateError([n,e],`Failed to stop PostgreSQL process ${t}.`)}}}async function w(t,n){try{await c({dataDir:t,mode:`immediate`,timeoutMs:f})}catch(e){throw AggregateError([n,e],`Temporary PostgreSQL failed to start and could not be stopped for ${t}.`)}await e.rm(t,{force:!0,recursive:!0})}function T(e){return{env:e,async[Symbol.asyncDispose](){}}}function E(e,t,n){let r;return{env:n,async[Symbol.asyncDispose](){r??=(async()=>{try{await e.release(t)}finally{e.close()}})(),await r}}}async function D(n){let i;try{i=await e.readFile(r.join(n,`postmaster.pid`),`utf8`)}catch{return}let[a,,,o,,s]=i.split(/\r?\n/),c=Number(a);if(!Number.isSafeInteger(c)||c<=0)return;try{t.kill(c,0)}catch(e){if(!A(e)||e.code!==`EPERM`)return}let l=Number(o);if(!Number.isSafeInteger(l)||l<=0||l>65535||!s)throw Error(`Cannot read connection details for PostgreSQL process ${c} from ${n}.`);return{host:s,pid:c,port:l}}function O(e,t,{host:n,port:r}){let i=new URL(`postgresql://${n}:${r}/${u}`);return i.username=m.name,i.password=m.password,y(e,{DATABASE_URL:i.href,PGDATA:t,PGDATABASE:u,PGHOST:n,PGPASSWORD:m.password,PGPORT:String(r),PGUSER:m.name})}async function k(t,n){if(t instanceof s)return new h(t.dataDir,t.pid,{cause:t});let r=t instanceof Error?t.message:String(t),i;if(n)try{i=(await e.readFile(n,`utf8`)).trim()||void 0}catch{}let a=i?`\n\nPostgreSQL output:\n${i}`:``,o=n?`\n\nPostgreSQL log: ${n}`:``;return Error(`Local PostgreSQL failed to start: ${r}${a}${o}`,{cause:t})}function A(e){return e instanceof Error}function j(e=process.env){let t=e.DATABASE_URL||M(e);if(!t)throw Error(`DATABASE_URL or PGDATABASE, PGHOST, PGPORT, and PGUSER are required.`);return t}function M(e){let{PGDATABASE:t,PGHOST:n,PGPASSWORD:r,PGPORT:i,PGUSER:a}=e;if(!t||!n||!i||!a)return;let o=new URL(`postgresql://${n}:${i}/${t}`);return o.username=a,r&&(o.password=r),o.href}export{l as LOCAL_POSTGRES_ENV_FLAG,h as ProjectPostgresAlreadyRunningError,b as createLocalPostgresDb,y as createLocalPostgresEnv,j as getLocalPostgresConnectionString,g as startProjectPostgres,v as startTemporaryProjectPostgres,_ as stopProjectPostgres};
|
package/dist/migrate.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { readProjectConfig } from "@coreframe/config";
|
|
2
|
+
|
|
1
3
|
//#region src/migrate.d.ts
|
|
2
4
|
type MigrateLocalDbOptions = {
|
|
5
|
+
config?: Awaited<ReturnType<typeof readProjectConfig>>;
|
|
6
|
+
cwd?: string;
|
|
3
7
|
env?: NodeJS.ProcessEnv;
|
|
4
8
|
};
|
|
5
9
|
declare function migrateLocalDb({
|
|
10
|
+
config,
|
|
11
|
+
cwd,
|
|
6
12
|
env
|
|
7
13
|
}?: MigrateLocalDbOptions): Promise<void>;
|
|
8
14
|
//#endregion
|
package/dist/migrate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MIGRATIONS_FOLDER as e}from"./config.js";import{createLocalPostgresDb as
|
|
1
|
+
import{MIGRATIONS_FOLDER as e}from"./config.js";import{createProjectSqliteDrizzleDatabase as t}from"./project.js";import{createLocalPostgresDb as n,startProjectPostgres as r}from"./local-postgres.js";import i from"./_virtual/_@oxc-project_runtime@0.138.0/helpers/esm/usingCtx.js";import{access as a}from"node:fs/promises";import{resolve as o}from"node:path";import{readProjectConfig as s}from"@coreframe/config";import{migrate as c}from"drizzle-orm/libsql/migrator";import{migrate as l}from"drizzle-orm/node-postgres/migrator";async function u({config:u,cwd:d=process.cwd(),env:f=process.env}={}){try{var p=i();let m=u??await s({cwd:d}),h=o(d,e);if(await a(h),m.database?.dialect===`sqlite`){let e=await t({cwd:d,env:f});try{await c(e,{migrationsFolder:h}),console.log(`Applied local migrations from ${h}`)}finally{await e.$client?.close?.()}return}let g=await n({cwd:d,env:p.a(await r({env:f,useSupervisorLease:!0})).env});try{await l(g,{migrationsFolder:h}),console.log(`Applied local migrations from ${h}`)}finally{await g.$client.end()}}catch(e){p.e=e}finally{await p.d()}}export{u as migrateLocalDb};
|
package/dist/project.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { DatabaseConfig } from "@coreframe/config";
|
|
|
4
4
|
//#region src/project.d.ts
|
|
5
5
|
type CreateProjectDatabaseOptions = {
|
|
6
6
|
config?: DatabaseConfig;
|
|
7
|
+
cwd?: string;
|
|
7
8
|
env?: NodeJS.ProcessEnv;
|
|
8
9
|
};
|
|
9
10
|
type DrizzleDatabase = DrizzleExecutor & {
|
|
@@ -14,10 +15,16 @@ type DrizzleDatabase = DrizzleExecutor & {
|
|
|
14
15
|
};
|
|
15
16
|
declare function createProjectDeployDatabase({
|
|
16
17
|
config,
|
|
18
|
+
cwd,
|
|
17
19
|
env
|
|
18
20
|
}?: CreateProjectDatabaseOptions): Promise<DatabaseClient>;
|
|
19
21
|
declare function createProjectPostgresDrizzleDatabase({
|
|
22
|
+
cwd,
|
|
23
|
+
env
|
|
24
|
+
}?: CreateProjectDatabaseOptions): Promise<DrizzleDatabase>;
|
|
25
|
+
declare function createProjectSqliteDrizzleDatabase({
|
|
26
|
+
cwd,
|
|
20
27
|
env
|
|
21
28
|
}?: CreateProjectDatabaseOptions): Promise<DrizzleDatabase>;
|
|
22
29
|
//#endregion
|
|
23
|
-
export { CreateProjectDatabaseOptions, createProjectDeployDatabase, createProjectPostgresDrizzleDatabase };
|
|
30
|
+
export { CreateProjectDatabaseOptions, createProjectDeployDatabase, createProjectPostgresDrizzleDatabase, createProjectSqliteDrizzleDatabase };
|
package/dist/project.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDatabaseAdapter as e}from"./client.js";import{importProjectDependency as t,importProjectModule as n,readProjectConfig as r}from"@coreframe/config";const i=`src/db/relations.ts`;async function a({config:e,
|
|
1
|
+
import{createDatabaseAdapter as e}from"./client.js";import{importProjectDependency as t,importProjectModule as n,readProjectConfig as r}from"@coreframe/config";const i=`src/db/relations.ts`;async function a({config:e,cwd:t=process.cwd(),env:n=process.env}={}){let i=(e??(await r({cwd:t})).database)?.dialect??`postgres`;if(i===`postgres`)return c({cwd:t,env:n});if(i===`sqlite`)return l({cwd:t,env:n});throw Error(`Unsupported database dialect "${i}".`)}async function o({cwd:e=process.cwd(),env:r=process.env}={}){let a=r.DATABASE_URL;if(!a)throw Error(`DATABASE_URL is required to create the PostgreSQL database.`);let[{drizzle:o},{relations:s}]=await Promise.all([t(`drizzle-orm/node-postgres`,e),n(i,e)]);return o({connection:{connectionString:a,max:1},relations:s})}async function s({cwd:e=process.cwd(),env:r=process.env}={}){let a=r.TURSO_DATABASE_URL??r.DATABASE_URL;if(!a)throw Error(`TURSO_DATABASE_URL or DATABASE_URL is required to create the SQLite database.`);let[{createClient:o},{drizzle:s},{relations:c}]=await Promise.all([t(`@libsql/client`,e),t(`drizzle-orm/libsql`,e),n(i,e)]),l=o({url:a,authToken:r.TURSO_AUTH_TOKEN}),u=s({client:l,relations:c});return u.$client||=l,u}async function c({cwd:t,env:n}){let r=await o({cwd:t,env:n});return e({database:r,dialect:`postgres`,close:()=>r.$client?.end?.()??Promise.resolve()})}async function l({cwd:t,env:n}){let r=await s({cwd:t,env:n});return e({database:r,dialect:`sqlite`,close:async()=>{await r.$client?.close?.()}})}export{a as createProjectDeployDatabase,o as createProjectPostgresDrizzleDatabase,s as createProjectSqliteDrizzleDatabase};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/db",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Database setup, migration, seeding, and local PostgreSQL utilities for Coreframe apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"import-meta-resolve": "^4.2.0",
|
|
23
23
|
"local-postgres": "0.3.1",
|
|
24
24
|
"nano-spawn": "^2.1.0",
|
|
25
|
-
"@coreframe/config": "^0.1.
|
|
26
|
-
"@coreframe/dev-supervisor": "^0.1.
|
|
25
|
+
"@coreframe/config": "^0.1.3",
|
|
26
|
+
"@coreframe/dev-supervisor": "^0.1.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^26.1.0",
|