@stacksjs/database 0.74.1 → 0.74.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.
Files changed (2) hide show
  1. package/dist/database.js +1 -1
  2. package/package.json +16 -16
package/dist/database.js CHANGED
@@ -1 +1 @@
1
- import{isVitessSharded,toQueryBuilderDialect}from"./dialect";import{qbSnapshotDir}from"./utils";import{createQueryBuilder,setConfig}from"@stacksjs/query-builder";import{env as stacksEnv}from"@stacksjs/env";export class Database{_queryBuilder=null;_options;_initialized=!1;constructor(options){this._options={verbose:!1,timestamps:{createdAt:"created_at",updatedAt:"updated_at",defaultOrderColumn:"created_at"},softDeletes:{enabled:!1,column:"deleted_at",defaultFilter:!0},...options}}get driver(){return this._options.driver}get connection(){return this._options.connection}get isInitialized(){return this._initialized}get query(){if(!this._queryBuilder)this.initialize();return this._queryBuilder}initialize(){if(this._initialized)return;setConfig({snapshotDir:qbSnapshotDir(),dialect:toQueryBuilderDialect(this._options.driver),vitess:{sharded:isVitessSharded(this._options.connection.sharded)},database:this._options.connection,verbose:this._options.verbose,timestamps:this._options.timestamps,softDeletes:this._options.softDeletes,hooks:this._options.hooks});this._queryBuilder=createQueryBuilder();this._initialized=!0}switchDriver(driver,connection){this.close();this._options.driver=driver;this._options.connection=connection;this._initialized=!1;this.initialize()}async close(){if(this._queryBuilder&&typeof this._queryBuilder.close==="function")await this._queryBuilder.close();this._queryBuilder=null;this._initialized=!1}static fromConfig(config,env){const driver=config.default;let connection;switch(driver){case"sqlite":{connection={database:env==="testing"?config.connections.sqlite?.database?.replace(".sqlite","_testing.sqlite")||"database/stacks_testing.sqlite":config.connections.sqlite?.database||"database/stacks.sqlite"};break}case"mysql":{const mysql=config.connections.mysql;connection={database:mysql?.name||"stacks",host:mysql?.host||"127.0.0.1",port:mysql?.port||3306,username:mysql?.username||"root",password:mysql?.password||""};break}case"singlestore":{const singlestore=config.connections.singlestore;connection={database:singlestore?.name||"stacks",host:singlestore?.host||"127.0.0.1",port:singlestore?.port||3306,username:singlestore?.username||"root",password:singlestore?.password||""};break}case"postgres":{const postgres=config.connections.postgres,dbName=postgres?.name||"stacks";connection={database:env==="testing"?`${dbName}_testing`:dbName,host:postgres?.host||"127.0.0.1",port:postgres?.port||5432,username:postgres?.username||"",password:postgres?.password||""};break}case"dynamodb":throw Error("[database] DB_CONNECTION=dynamodb is not a SQL driver. Use the entity-style `dynamo.entity(...)` API for DynamoDB access, or set DB_CONNECTION to sqlite/mysql/postgres for SQL workloads.");default:throw Error(`[database] Unknown DB_CONNECTION "${String(driver)}". Allowed values: sqlite, mysql, postgres.`)}return new Database({driver,connection,verbose:env!=="production"})}static fromEnv(){const driver=stacksEnv.DB_CONNECTION||"sqlite";let connection;switch(driver){case"sqlite":connection={database:stacksEnv.DB_DATABASE||"database/stacks.sqlite"};break;case"mysql":case"singlestore":connection={database:stacksEnv.DB_DATABASE||"stacks",host:stacksEnv.DB_HOST||"127.0.0.1",port:stacksEnv.DB_PORT||3306,username:stacksEnv.DB_USERNAME||"root",password:stacksEnv.DB_PASSWORD||""};break;case"postgres":connection={database:stacksEnv.DB_DATABASE||"stacks",host:stacksEnv.DB_HOST||"127.0.0.1",port:stacksEnv.DB_PORT||5432,username:stacksEnv.DB_USERNAME||"",password:stacksEnv.DB_PASSWORD||""};break;default:connection={database:":memory:"}}return new Database({driver,connection,verbose:stacksEnv.APP_ENV!=="prod"})}}export function createDatabase(options){return new Database(options)}export function createSqliteDatabase(database,options){return new Database({driver:"sqlite",connection:{database},...options})}export function createPostgresDatabase(connection,options){return new Database({driver:"postgres",connection,...options})}export function createMysqlDatabase(connection,options){return new Database({driver:"mysql",connection,...options})}
1
+ import{isVitessSharded,toQueryBuilderDialect}from"./dialect";import{qbSnapshotDir,resetDatabaseConnection}from"./utils";import{createQueryBuilder,setConfig}from"@stacksjs/query-builder";import{env as stacksEnv}from"@stacksjs/env";export class Database{_queryBuilder=null;_options;_initialized=!1;constructor(options){this._options={verbose:!1,timestamps:{createdAt:"created_at",updatedAt:"updated_at",defaultOrderColumn:"created_at"},softDeletes:{enabled:!1,column:"deleted_at",defaultFilter:!0},...options}}get driver(){return this._options.driver}get connection(){return this._options.connection}get isInitialized(){return this._initialized}get query(){if(!this._queryBuilder)this.initialize();return this._queryBuilder}initialize(){if(this._initialized)return;setConfig({snapshotDir:qbSnapshotDir(),dialect:toQueryBuilderDialect(this._options.driver),vitess:{sharded:isVitessSharded(this._options.connection.sharded)},database:this._options.connection,verbose:this._options.verbose,timestamps:this._options.timestamps,softDeletes:this._options.softDeletes,hooks:this._options.hooks});this._queryBuilder=createQueryBuilder();this._initialized=!0}switchDriver(driver,connection){this.close();this._options.driver=driver;this._options.connection=connection;this._initialized=!1;this.initialize()}async close(){if(this._queryBuilder&&typeof this._queryBuilder.close==="function")await this._queryBuilder.close();this._queryBuilder=null;this._initialized=!1;resetDatabaseConnection()}static fromConfig(config,env){const driver=config.default;let connection;switch(driver){case"sqlite":{connection={database:env==="testing"?config.connections.sqlite?.database?.replace(".sqlite","_testing.sqlite")||"database/stacks_testing.sqlite":config.connections.sqlite?.database||"database/stacks.sqlite"};break}case"mysql":{const mysql=config.connections.mysql;connection={database:mysql?.name||"stacks",host:mysql?.host||"127.0.0.1",port:mysql?.port||3306,username:mysql?.username||"root",password:mysql?.password||""};break}case"singlestore":{const singlestore=config.connections.singlestore;connection={database:singlestore?.name||"stacks",host:singlestore?.host||"127.0.0.1",port:singlestore?.port||3306,username:singlestore?.username||"root",password:singlestore?.password||""};break}case"postgres":{const postgres=config.connections.postgres,dbName=postgres?.name||"stacks";connection={database:env==="testing"?`${dbName}_testing`:dbName,host:postgres?.host||"127.0.0.1",port:postgres?.port||5432,username:postgres?.username||"",password:postgres?.password||""};break}case"dynamodb":throw Error("[database] DB_CONNECTION=dynamodb is not a SQL driver. Use the entity-style `dynamo.entity(...)` API for DynamoDB access, or set DB_CONNECTION to sqlite/mysql/postgres for SQL workloads.");default:throw Error(`[database] Unknown DB_CONNECTION "${String(driver)}". Allowed values: sqlite, mysql, postgres.`)}return new Database({driver,connection,verbose:env!=="production"})}static fromEnv(){const driver=stacksEnv.DB_CONNECTION||"sqlite";let connection;switch(driver){case"sqlite":connection={database:stacksEnv.DB_DATABASE||"database/stacks.sqlite"};break;case"mysql":case"singlestore":connection={database:stacksEnv.DB_DATABASE||"stacks",host:stacksEnv.DB_HOST||"127.0.0.1",port:stacksEnv.DB_PORT||3306,username:stacksEnv.DB_USERNAME||"root",password:stacksEnv.DB_PASSWORD||""};break;case"postgres":connection={database:stacksEnv.DB_DATABASE||"stacks",host:stacksEnv.DB_HOST||"127.0.0.1",port:stacksEnv.DB_PORT||5432,username:stacksEnv.DB_USERNAME||"",password:stacksEnv.DB_PASSWORD||""};break;default:connection={database:":memory:"}}return new Database({driver,connection,verbose:stacksEnv.APP_ENV!=="prod"})}}export function createDatabase(options){return new Database(options)}export function createSqliteDatabase(database,options){return new Database({driver:"sqlite",connection:{database},...options})}export function createPostgresDatabase(connection,options){return new Database({driver:"postgres",connection,...options})}export function createMysqlDatabase(connection,options){return new Database({driver:"mysql",connection,...options})}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/database",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.74.1",
5
+ "version": "0.74.3",
6
6
  "description": "The Stacks database integration.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -60,26 +60,26 @@
60
60
  "prepublishOnly": "bun run build"
61
61
  },
62
62
  "dependencies": {
63
- "@stacksjs/buddy": "0.74.1",
64
- "@stacksjs/config": "0.74.1",
65
- "@stacksjs/env": "0.74.1",
66
- "@stacksjs/error-handling": "0.74.1",
67
- "@stacksjs/faker": "^0.74.1",
68
- "@stacksjs/logging": "0.74.1",
69
- "@stacksjs/orm": "0.74.1",
70
- "@stacksjs/path": "0.74.1",
71
- "@stacksjs/query-builder": "^0.74.1",
72
- "@stacksjs/security": "0.74.1",
73
- "@stacksjs/storage": "0.74.1",
74
- "@stacksjs/strings": "0.74.1",
63
+ "@stacksjs/buddy": "0.74.3",
64
+ "@stacksjs/config": "0.74.3",
65
+ "@stacksjs/env": "0.74.3",
66
+ "@stacksjs/error-handling": "0.74.3",
67
+ "@stacksjs/faker": "^0.74.3",
68
+ "@stacksjs/logging": "0.74.3",
69
+ "@stacksjs/orm": "0.74.3",
70
+ "@stacksjs/path": "0.74.3",
71
+ "@stacksjs/query-builder": "^0.74.3",
72
+ "@stacksjs/security": "0.74.3",
73
+ "@stacksjs/storage": "0.74.3",
74
+ "@stacksjs/strings": "0.74.3",
75
75
  "@stacksjs/ts-validation": "^0.5.6",
76
76
  "bun-query-builder": "^0.2.53",
77
77
  "dynamodb-tooling": "^0.3.2"
78
78
  },
79
79
  "devDependencies": {
80
- "@stacksjs/cli": "0.74.1",
81
- "@stacksjs/router": "0.74.1",
82
- "@stacksjs/utils": "0.74.1",
80
+ "@stacksjs/cli": "0.74.3",
81
+ "@stacksjs/router": "0.74.3",
82
+ "@stacksjs/utils": "0.74.3",
83
83
  "better-dx": "^0.2.24"
84
84
  }
85
85
  }