@h3ravel/database 11.0.0 → 11.1.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.
package/README.md CHANGED
@@ -1,8 +1,16 @@
1
- <p align="center"><a href="https://h3ravel.toneflix.net" target="_blank"><img src="https://raw.githubusercontent.com/h3ravel/assets/refs/heads/main/logo-full.svg" width="400" alt="H3ravel Logo"></a></p>
1
+ <div align="center">
2
+ <a href="https://h3ravel.toneflix.net" target="_blank">
3
+ <img src="https://raw.githubusercontent.com/h3ravel/assets/refs/heads/main/logo-full.svg" width="200" alt="H3ravel Logo">
4
+ </a>
5
+ <h1 align="center"><a href="https://h3ravel.toneflix.net/arquebus">H3ravel Database</a></h1>
2
6
 
3
7
  [![Framework][ix]][lx]
4
8
  [![Database Package Version][i1]][l1]
5
9
  [![Downloads][d1]][d1]
10
+ [![Tests][tei]][tel]
11
+ [![License][lini]][linl]
12
+
13
+ </div>
6
14
 
7
15
  # About H3ravel/database
8
16
 
@@ -29,3 +37,7 @@ The H3ravel framework is open-sourced software licensed under the [MIT license](
29
37
  [i1]: https://img.shields.io/npm/v/%40h3ravel%2Fdatabase?style=flat-square&label=@h3ravel/database&color=%230970ce
30
38
  [l1]: https://www.npmjs.com/package/@h3ravel/database
31
39
  [d1]: https://img.shields.io/npm/dt/%40h3ravel%2Fdatabase?style=flat-square&label=Downloads&link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40h3ravel%2Fdatabase
40
+ [linl]: https://github.com/h3ravel/framework/blob/main/LICENSE
41
+ [lini]: https://img.shields.io/github/license/h3ravel/framework
42
+ [tel]: https://github.com/h3ravel/framework/actions/workflows/test.yml
43
+ [tei]: https://github.com/h3ravel/framework/actions/workflows/test.yml/badge.svg
package/dist/index.cjs CHANGED
@@ -1,42 +1,124 @@
1
- "use strict";
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
8
  var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let __h3ravel_arquebus = require("@h3ravel/arquebus");
25
+ __h3ravel_arquebus = __toESM(__h3ravel_arquebus);
26
+ let __h3ravel_core = require("@h3ravel/core");
27
+ __h3ravel_core = __toESM(__h3ravel_core);
28
+
29
+ //#region src/Configuration.ts
30
+ const arquebusConfig = (config) => {
31
+ return {
32
+ sqlite: {
33
+ client: config.connections.sqlite.driver,
34
+ connection: {
35
+ filename: database_path(config.connections.sqlite.database),
36
+ debug: config.connections.sqlite.debug,
37
+ flags: config.connections.sqlite.flags,
38
+ options: config.connections.sqlite.options,
39
+ expirationChecker: config.connections.sqlite.expirationChecker
40
+ },
41
+ useNullAsDefault: config.connections.sqlite.useNullAsDefault
42
+ },
43
+ mysql: {
44
+ client: config.connections.mysql.driver,
45
+ connection: {
46
+ host: config.connections.mysql.host ?? "localhost",
47
+ port: config.connections.mysql.port ?? 3306,
48
+ user: config.connections.mysql.username ?? "root",
49
+ password: config.connections.mysql.password,
50
+ database: config.connections.mysql.database,
51
+ charset: config.connections.mysql.charset,
52
+ socketPath: config.connections.mysql.unix_socket,
53
+ localAddress: config.connections.mysql.url
54
+ }
55
+ },
56
+ mariadb: {
57
+ client: config.connections.mariadb.driver,
58
+ connection: {
59
+ host: config.connections.mariadb.host ?? "localhost",
60
+ port: config.connections.mariadb.port ?? 3306,
61
+ user: config.connections.mariadb.username ?? "root",
62
+ password: config.connections.mariadb.password,
63
+ database: config.connections.mariadb.database,
64
+ charset: config.connections.mariadb.charset,
65
+ socketPath: config.connections.mariadb.unix_socket,
66
+ localAddress: config.connections.mariadb.url,
67
+ expirationChecker: config.connections.mariadb.expirationChecker
68
+ }
69
+ },
70
+ pgsql: {
71
+ client: "pg",
72
+ connection: {
73
+ host: config.connections.pgsql.host ?? "localhost",
74
+ port: config.connections.pgsql.port ?? 3306,
75
+ user: config.connections.pgsql.username ?? "root",
76
+ password: config.connections.pgsql.password,
77
+ database: config.connections.pgsql.database,
78
+ charset: config.connections.mysql.charset,
79
+ connectionString: config.connections.pgsql.url,
80
+ expirationChecker: config.connections.pgsql.expirationChecker
81
+ }
82
+ }
83
+ };
18
84
  };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
85
 
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- DatabaseServiceProvider: () => DatabaseServiceProvider
25
- });
26
- module.exports = __toCommonJS(index_exports);
86
+ //#endregion
87
+ //#region src/Model.ts
88
+ var Model = class extends __h3ravel_arquebus.Model {
89
+ /**
90
+ * Retrieve the model for a bound value.
91
+ *
92
+ * @param {any} value
93
+ * @param {String|null} field
94
+ * @returns
95
+ */
96
+ resolveRouteBinding(value, field = null) {
97
+ return this.newQuery().where(field ?? "ids", value).firstOrFail();
98
+ }
99
+ };
27
100
 
28
- // src/Providers/DatabaseServiceProvider.ts
29
- var import_core = require("@h3ravel/core");
30
- var DatabaseServiceProvider = class extends import_core.ServiceProvider {
31
- static {
32
- __name(this, "DatabaseServiceProvider");
33
- }
34
- static priority = 994;
35
- register() {
36
- }
101
+ //#endregion
102
+ //#region src/Providers/DatabaseServiceProvider.ts
103
+ /**
104
+ * Database connection, ORM, migrations.
105
+ *
106
+ * Register DatabaseManager and QueryBuilder if required.
107
+ * Set up ORM models and relationships.
108
+ * Register migration and seeder commands.
109
+ *
110
+ */
111
+ var DatabaseServiceProvider = class extends __h3ravel_core.ServiceProvider {
112
+ static priority = 994;
113
+ register() {
114
+ const config = this.app.make("config");
115
+ const connection = Object.entries(arquebusConfig(config.get("database"))).find(([client]) => client === config.get("database.default"))?.at(1);
116
+ if (connection) __h3ravel_arquebus.arquebus.addConnection(connection);
117
+ }
37
118
  };
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- DatabaseServiceProvider
41
- });
119
+
120
+ //#endregion
121
+ exports.DatabaseServiceProvider = DatabaseServiceProvider;
122
+ exports.Model = Model;
123
+ exports.arquebusConfig = arquebusConfig;
42
124
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Providers/DatabaseServiceProvider.ts"],"sourcesContent":["export * from './Model'\nexport * from './Providers/DatabaseServiceProvider'\n","import { ServiceProvider } from '@h3ravel/core'\n\n/**\n * Database connection, ORM, migrations.\n * \n * Register DatabaseManager and QueryBuilder if required.\n * Set up ORM models and relationships.\n * Register migration and seeder commands.\n * \n * Auto-Registered if @h3ravel/database is installed\n */\nexport class DatabaseServiceProvider extends ServiceProvider {\n public static priority = 994;\n\n register () {\n // Core bindings\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACAA,kBAAgC;AAWzB,IAAMA,0BAAN,cAAsCC,4BAAAA;EAX7C,OAW6CA;;;EACzC,OAAcC,WAAW;EAEzBC,WAAY;EAEZ;AACJ;","names":["DatabaseServiceProvider","ServiceProvider","priority","register"]}
1
+ {"version":3,"file":"index.cjs","names":["BaseModel","ServiceProvider"],"sources":["../src/Configuration.ts","../src/Model.ts","../src/Providers/DatabaseServiceProvider.ts"],"sourcesContent":["/// <reference path=\"../../core/src/app.globals.d.ts\" />\nimport { Knex } from \"knex\";\n\ntype TFunction = (...args: any[]) => any\n\nexport interface TField {\n type: 'VAR_STRING' | 'BLOB' | 'DATETIME' | 'TIMESTAMP' | 'LONG' | 'JSON'\n length: number\n db: string\n table: string\n name: string\n string: TFunction,\n buffer: TFunction\n geometry: TFunction\n}\n\nexport interface TBaseConfig {\n client: 'mysql' | 'mysql2' | 'sqlite3' | 'oracle' | 'mariadb' | 'pg'\n connection: {\n typeCast?(field: TField, next: TFunction): any\n dateStrings?: boolean\n }\n pool?: {\n afterCreate: (connection: TConfig, callback: (val: any, con: any) => void) => Promise<any>\n } | undefined\n connections?: Record<string, TConfig>\n migrations?: {\n table: string\n path: string\n },\n factories?: {\n path: string\n },\n seeders?: {\n path: string\n },\n models?: {\n path: string\n }\n}\n\nexport type TConfig = TBaseConfig & ({\n client: 'pg'\n connection: Knex.PgConnectionConfig\n} | {\n client: 'oracle'\n connection: Knex.OracleDbConnectionConfig\n} | {\n client: 'mysql2'\n connection: Knex.MySql2ConnectionConfig\n} | {\n client: 'mysql'\n connection: Knex.MySqlConnectionConfig\n} | {\n client: 'sqlite3'\n connection: Knex.Sqlite3ConnectionConfig\n useNullAsDefault?: boolean\n} | {\n client: 'mariadb'\n connection: Knex.MariaSqlConnectionConfig\n useNullAsDefault?: boolean\n})\n\nexport const arquebusConfig = (config: any) => {\n return {\n sqlite: {\n client: config.connections.sqlite.driver,\n connection: <Knex.Sqlite3ConnectionConfig>{\n filename: database_path(config.connections.sqlite.database),\n debug: config.connections.sqlite.debug,\n flags: config.connections.sqlite.flags,\n options: config.connections.sqlite.options,\n expirationChecker: config.connections.sqlite.expirationChecker\n },\n useNullAsDefault: config.connections.sqlite.useNullAsDefault,\n },\n mysql: {\n client: config.connections.mysql.driver,\n connection: <Knex.MySql2ConnectionConfig>{\n host: config.connections.mysql.host ?? 'localhost',\n port: config.connections.mysql.port ?? 3306,\n user: config.connections.mysql.username ?? 'root',\n password: config.connections.mysql.password,\n database: config.connections.mysql.database,\n charset: config.connections.mysql.charset,\n socketPath: config.connections.mysql.unix_socket,\n localAddress: config.connections.mysql.url,\n },\n },\n mariadb: {\n client: config.connections.mariadb.driver,\n connection: <Knex.MariaSqlConnectionConfig>{\n host: config.connections.mariadb.host ?? 'localhost',\n port: config.connections.mariadb.port ?? 3306,\n user: config.connections.mariadb.username ?? 'root',\n password: config.connections.mariadb.password,\n database: config.connections.mariadb.database,\n charset: config.connections.mariadb.charset,\n socketPath: config.connections.mariadb.unix_socket,\n localAddress: config.connections.mariadb.url,\n expirationChecker: config.connections.mariadb.expirationChecker\n },\n },\n pgsql: {\n client: 'pg',\n connection: <Knex.PgConnectionConfig>{\n host: config.connections.pgsql.host ?? 'localhost',\n port: config.connections.pgsql.port ?? 3306,\n user: config.connections.pgsql.username ?? 'root',\n password: config.connections.pgsql.password,\n database: config.connections.pgsql.database,\n charset: config.connections.mysql.charset,\n connectionString: config.connections.pgsql.url,\n expirationChecker: config.connections.pgsql.expirationChecker\n },\n }\n } as unknown as TBaseConfig\n}\n","import { Model as BaseModel } from \"@h3ravel/arquebus\";\n\nexport class Model<M extends BaseModel = any> extends BaseModel {\n /**\n * Retrieve the model for a bound value.\n * \n * @param {any} value \n * @param {String|null} field \n * @returns \n */\n public resolveRouteBinding (value: any, field: undefined | string | null = null): Promise<M> {\n return this.newQuery().where(field ?? 'ids', value).firstOrFail()! as Promise<M>;\n }\n}\n","import { ServiceProvider } from '@h3ravel/core'\nimport { arquebus } from '@h3ravel/arquebus';\nimport { arquebusConfig } from '../Configuration';\n\n/**\n * Database connection, ORM, migrations.\n * \n * Register DatabaseManager and QueryBuilder if required.\n * Set up ORM models and relationships.\n * Register migration and seeder commands.\n * \n */\nexport class DatabaseServiceProvider extends ServiceProvider {\n public static priority = 994;\n\n register () {\n const config = this.app.make('config')\n\n const connection = Object.entries(arquebusConfig(config.get('database')))\n .find(([client]) => client === config.get('database.default'))\n ?.at(1)\n\n if (connection) {\n arquebus.addConnection(connection);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAa,kBAAkB,WAAgB;AAC3C,QAAO;EACH,QAAQ;GACJ,QAAQ,OAAO,YAAY,OAAO;GAClC,YAA0C;IACtC,UAAU,cAAc,OAAO,YAAY,OAAO,SAAS;IAC3D,OAAO,OAAO,YAAY,OAAO;IACjC,OAAO,OAAO,YAAY,OAAO;IACjC,SAAS,OAAO,YAAY,OAAO;IACnC,mBAAmB,OAAO,YAAY,OAAO;IAChD;GACD,kBAAkB,OAAO,YAAY,OAAO;GAC/C;EACD,OAAO;GACH,QAAQ,OAAO,YAAY,MAAM;GACjC,YAAyC;IACrC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,YAAY;IAC3C,UAAU,OAAO,YAAY,MAAM;IACnC,UAAU,OAAO,YAAY,MAAM;IACnC,SAAS,OAAO,YAAY,MAAM;IAClC,YAAY,OAAO,YAAY,MAAM;IACrC,cAAc,OAAO,YAAY,MAAM;IAC1C;GACJ;EACD,SAAS;GACL,QAAQ,OAAO,YAAY,QAAQ;GACnC,YAA2C;IACvC,MAAM,OAAO,YAAY,QAAQ,QAAQ;IACzC,MAAM,OAAO,YAAY,QAAQ,QAAQ;IACzC,MAAM,OAAO,YAAY,QAAQ,YAAY;IAC7C,UAAU,OAAO,YAAY,QAAQ;IACrC,UAAU,OAAO,YAAY,QAAQ;IACrC,SAAS,OAAO,YAAY,QAAQ;IACpC,YAAY,OAAO,YAAY,QAAQ;IACvC,cAAc,OAAO,YAAY,QAAQ;IACzC,mBAAmB,OAAO,YAAY,QAAQ;IACjD;GACJ;EACD,OAAO;GACH,QAAQ;GACR,YAAqC;IACjC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,YAAY;IAC3C,UAAU,OAAO,YAAY,MAAM;IACnC,UAAU,OAAO,YAAY,MAAM;IACnC,SAAS,OAAO,YAAY,MAAM;IAClC,kBAAkB,OAAO,YAAY,MAAM;IAC3C,mBAAmB,OAAO,YAAY,MAAM;IAC/C;GACJ;EACJ;;;;;AClHL,IAAa,QAAb,cAAsDA,yBAAU;;;;;;;;CAQ5D,AAAO,oBAAqB,OAAY,QAAmC,MAAkB;AACzF,SAAO,KAAK,UAAU,CAAC,MAAM,SAAS,OAAO,MAAM,CAAC,aAAa;;;;;;;;;;;;;;ACCzE,IAAa,0BAAb,cAA6CC,+BAAgB;CACzD,OAAc,WAAW;CAEzB,WAAY;EACR,MAAM,SAAS,KAAK,IAAI,KAAK,SAAS;EAEtC,MAAM,aAAa,OAAO,QAAQ,eAAe,OAAO,IAAI,WAAW,CAAC,CAAC,CACpE,MAAM,CAAC,YAAY,WAAW,OAAO,IAAI,mBAAmB,CAAC,EAC5D,GAAG,EAAE;AAEX,MAAI,WACA,6BAAS,cAAc,WAAW"}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,79 @@
1
- import { ServiceProvider } from '@h3ravel/core';
1
+ import { Knex } from "knex";
2
+ import { Model as Model$1 } from "@h3ravel/arquebus";
3
+ import { ServiceProvider } from "@h3ravel/core";
2
4
 
5
+ //#region src/Configuration.d.ts
6
+ type TFunction = (...args: any[]) => any;
7
+ interface TField {
8
+ type: 'VAR_STRING' | 'BLOB' | 'DATETIME' | 'TIMESTAMP' | 'LONG' | 'JSON';
9
+ length: number;
10
+ db: string;
11
+ table: string;
12
+ name: string;
13
+ string: TFunction;
14
+ buffer: TFunction;
15
+ geometry: TFunction;
16
+ }
17
+ interface TBaseConfig {
18
+ client: 'mysql' | 'mysql2' | 'sqlite3' | 'oracle' | 'mariadb' | 'pg';
19
+ connection: {
20
+ typeCast?(field: TField, next: TFunction): any;
21
+ dateStrings?: boolean;
22
+ };
23
+ pool?: {
24
+ afterCreate: (connection: TConfig, callback: (val: any, con: any) => void) => Promise<any>;
25
+ } | undefined;
26
+ connections?: Record<string, TConfig>;
27
+ migrations?: {
28
+ table: string;
29
+ path: string;
30
+ };
31
+ factories?: {
32
+ path: string;
33
+ };
34
+ seeders?: {
35
+ path: string;
36
+ };
37
+ models?: {
38
+ path: string;
39
+ };
40
+ }
41
+ type TConfig = TBaseConfig & ({
42
+ client: 'pg';
43
+ connection: Knex.PgConnectionConfig;
44
+ } | {
45
+ client: 'oracle';
46
+ connection: Knex.OracleDbConnectionConfig;
47
+ } | {
48
+ client: 'mysql2';
49
+ connection: Knex.MySql2ConnectionConfig;
50
+ } | {
51
+ client: 'mysql';
52
+ connection: Knex.MySqlConnectionConfig;
53
+ } | {
54
+ client: 'sqlite3';
55
+ connection: Knex.Sqlite3ConnectionConfig;
56
+ useNullAsDefault?: boolean;
57
+ } | {
58
+ client: 'mariadb';
59
+ connection: Knex.MariaSqlConnectionConfig;
60
+ useNullAsDefault?: boolean;
61
+ });
62
+ declare const arquebusConfig: (config: any) => TBaseConfig;
63
+ //#endregion
64
+ //#region src/Model.d.ts
65
+ declare class Model<M extends Model$1 = any> extends Model$1 {
66
+ /**
67
+ * Retrieve the model for a bound value.
68
+ *
69
+ * @param {any} value
70
+ * @param {String|null} field
71
+ * @returns
72
+ */
73
+ resolveRouteBinding(value: any, field?: undefined | string | null): Promise<M>;
74
+ }
75
+ //#endregion
76
+ //#region src/Providers/DatabaseServiceProvider.d.ts
3
77
  /**
4
78
  * Database connection, ORM, migrations.
5
79
  *
@@ -7,11 +81,11 @@ import { ServiceProvider } from '@h3ravel/core';
7
81
  * Set up ORM models and relationships.
8
82
  * Register migration and seeder commands.
9
83
  *
10
- * Auto-Registered if @h3ravel/database is installed
11
84
  */
12
85
  declare class DatabaseServiceProvider extends ServiceProvider {
13
- static priority: number;
14
- register(): void;
86
+ static priority: number;
87
+ register(): void;
15
88
  }
16
-
17
- export { DatabaseServiceProvider };
89
+ //#endregion
90
+ export { DatabaseServiceProvider, Model, TBaseConfig, TConfig, TField, arquebusConfig };
91
+ //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,79 @@
1
- import { ServiceProvider } from '@h3ravel/core';
1
+ import { Model as Model$1 } from "@h3ravel/arquebus";
2
+ import { ServiceProvider } from "@h3ravel/core";
3
+ import { Knex } from "knex";
2
4
 
5
+ //#region src/Configuration.d.ts
6
+ type TFunction = (...args: any[]) => any;
7
+ interface TField {
8
+ type: 'VAR_STRING' | 'BLOB' | 'DATETIME' | 'TIMESTAMP' | 'LONG' | 'JSON';
9
+ length: number;
10
+ db: string;
11
+ table: string;
12
+ name: string;
13
+ string: TFunction;
14
+ buffer: TFunction;
15
+ geometry: TFunction;
16
+ }
17
+ interface TBaseConfig {
18
+ client: 'mysql' | 'mysql2' | 'sqlite3' | 'oracle' | 'mariadb' | 'pg';
19
+ connection: {
20
+ typeCast?(field: TField, next: TFunction): any;
21
+ dateStrings?: boolean;
22
+ };
23
+ pool?: {
24
+ afterCreate: (connection: TConfig, callback: (val: any, con: any) => void) => Promise<any>;
25
+ } | undefined;
26
+ connections?: Record<string, TConfig>;
27
+ migrations?: {
28
+ table: string;
29
+ path: string;
30
+ };
31
+ factories?: {
32
+ path: string;
33
+ };
34
+ seeders?: {
35
+ path: string;
36
+ };
37
+ models?: {
38
+ path: string;
39
+ };
40
+ }
41
+ type TConfig = TBaseConfig & ({
42
+ client: 'pg';
43
+ connection: Knex.PgConnectionConfig;
44
+ } | {
45
+ client: 'oracle';
46
+ connection: Knex.OracleDbConnectionConfig;
47
+ } | {
48
+ client: 'mysql2';
49
+ connection: Knex.MySql2ConnectionConfig;
50
+ } | {
51
+ client: 'mysql';
52
+ connection: Knex.MySqlConnectionConfig;
53
+ } | {
54
+ client: 'sqlite3';
55
+ connection: Knex.Sqlite3ConnectionConfig;
56
+ useNullAsDefault?: boolean;
57
+ } | {
58
+ client: 'mariadb';
59
+ connection: Knex.MariaSqlConnectionConfig;
60
+ useNullAsDefault?: boolean;
61
+ });
62
+ declare const arquebusConfig: (config: any) => TBaseConfig;
63
+ //#endregion
64
+ //#region src/Model.d.ts
65
+ declare class Model<M extends Model$1 = any> extends Model$1 {
66
+ /**
67
+ * Retrieve the model for a bound value.
68
+ *
69
+ * @param {any} value
70
+ * @param {String|null} field
71
+ * @returns
72
+ */
73
+ resolveRouteBinding(value: any, field?: undefined | string | null): Promise<M>;
74
+ }
75
+ //#endregion
76
+ //#region src/Providers/DatabaseServiceProvider.d.ts
3
77
  /**
4
78
  * Database connection, ORM, migrations.
5
79
  *
@@ -7,11 +81,11 @@ import { ServiceProvider } from '@h3ravel/core';
7
81
  * Set up ORM models and relationships.
8
82
  * Register migration and seeder commands.
9
83
  *
10
- * Auto-Registered if @h3ravel/database is installed
11
84
  */
12
85
  declare class DatabaseServiceProvider extends ServiceProvider {
13
- static priority: number;
14
- register(): void;
86
+ static priority: number;
87
+ register(): void;
15
88
  }
16
-
17
- export { DatabaseServiceProvider };
89
+ //#endregion
90
+ export { DatabaseServiceProvider, Model, TBaseConfig, TConfig, TField, arquebusConfig };
91
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,17 +1,97 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/Providers/DatabaseServiceProvider.ts
1
+ import { Model as Model$1, arquebus } from "@h3ravel/arquebus";
5
2
  import { ServiceProvider } from "@h3ravel/core";
6
- var DatabaseServiceProvider = class extends ServiceProvider {
7
- static {
8
- __name(this, "DatabaseServiceProvider");
9
- }
10
- static priority = 994;
11
- register() {
12
- }
3
+
4
+ //#region src/Configuration.ts
5
+ const arquebusConfig = (config) => {
6
+ return {
7
+ sqlite: {
8
+ client: config.connections.sqlite.driver,
9
+ connection: {
10
+ filename: database_path(config.connections.sqlite.database),
11
+ debug: config.connections.sqlite.debug,
12
+ flags: config.connections.sqlite.flags,
13
+ options: config.connections.sqlite.options,
14
+ expirationChecker: config.connections.sqlite.expirationChecker
15
+ },
16
+ useNullAsDefault: config.connections.sqlite.useNullAsDefault
17
+ },
18
+ mysql: {
19
+ client: config.connections.mysql.driver,
20
+ connection: {
21
+ host: config.connections.mysql.host ?? "localhost",
22
+ port: config.connections.mysql.port ?? 3306,
23
+ user: config.connections.mysql.username ?? "root",
24
+ password: config.connections.mysql.password,
25
+ database: config.connections.mysql.database,
26
+ charset: config.connections.mysql.charset,
27
+ socketPath: config.connections.mysql.unix_socket,
28
+ localAddress: config.connections.mysql.url
29
+ }
30
+ },
31
+ mariadb: {
32
+ client: config.connections.mariadb.driver,
33
+ connection: {
34
+ host: config.connections.mariadb.host ?? "localhost",
35
+ port: config.connections.mariadb.port ?? 3306,
36
+ user: config.connections.mariadb.username ?? "root",
37
+ password: config.connections.mariadb.password,
38
+ database: config.connections.mariadb.database,
39
+ charset: config.connections.mariadb.charset,
40
+ socketPath: config.connections.mariadb.unix_socket,
41
+ localAddress: config.connections.mariadb.url,
42
+ expirationChecker: config.connections.mariadb.expirationChecker
43
+ }
44
+ },
45
+ pgsql: {
46
+ client: "pg",
47
+ connection: {
48
+ host: config.connections.pgsql.host ?? "localhost",
49
+ port: config.connections.pgsql.port ?? 3306,
50
+ user: config.connections.pgsql.username ?? "root",
51
+ password: config.connections.pgsql.password,
52
+ database: config.connections.pgsql.database,
53
+ charset: config.connections.mysql.charset,
54
+ connectionString: config.connections.pgsql.url,
55
+ expirationChecker: config.connections.pgsql.expirationChecker
56
+ }
57
+ }
58
+ };
59
+ };
60
+
61
+ //#endregion
62
+ //#region src/Model.ts
63
+ var Model = class extends Model$1 {
64
+ /**
65
+ * Retrieve the model for a bound value.
66
+ *
67
+ * @param {any} value
68
+ * @param {String|null} field
69
+ * @returns
70
+ */
71
+ resolveRouteBinding(value, field = null) {
72
+ return this.newQuery().where(field ?? "ids", value).firstOrFail();
73
+ }
13
74
  };
14
- export {
15
- DatabaseServiceProvider
75
+
76
+ //#endregion
77
+ //#region src/Providers/DatabaseServiceProvider.ts
78
+ /**
79
+ * Database connection, ORM, migrations.
80
+ *
81
+ * Register DatabaseManager and QueryBuilder if required.
82
+ * Set up ORM models and relationships.
83
+ * Register migration and seeder commands.
84
+ *
85
+ */
86
+ var DatabaseServiceProvider = class extends ServiceProvider {
87
+ static priority = 994;
88
+ register() {
89
+ const config = this.app.make("config");
90
+ const connection = Object.entries(arquebusConfig(config.get("database"))).find(([client]) => client === config.get("database.default"))?.at(1);
91
+ if (connection) arquebus.addConnection(connection);
92
+ }
16
93
  };
94
+
95
+ //#endregion
96
+ export { DatabaseServiceProvider, Model, arquebusConfig };
17
97
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Providers/DatabaseServiceProvider.ts"],"sourcesContent":["import { ServiceProvider } from '@h3ravel/core'\n\n/**\n * Database connection, ORM, migrations.\n * \n * Register DatabaseManager and QueryBuilder if required.\n * Set up ORM models and relationships.\n * Register migration and seeder commands.\n * \n * Auto-Registered if @h3ravel/database is installed\n */\nexport class DatabaseServiceProvider extends ServiceProvider {\n public static priority = 994;\n\n register () {\n // Core bindings\n }\n}\n"],"mappings":";;;;AAAA,SAASA,uBAAuB;AAWzB,IAAMC,0BAAN,cAAsCC,gBAAAA;EAX7C,OAW6CA;;;EACzC,OAAcC,WAAW;EAEzBC,WAAY;EAEZ;AACJ;","names":["ServiceProvider","DatabaseServiceProvider","ServiceProvider","priority","register"]}
1
+ {"version":3,"file":"index.js","names":["BaseModel"],"sources":["../src/Configuration.ts","../src/Model.ts","../src/Providers/DatabaseServiceProvider.ts"],"sourcesContent":["/// <reference path=\"../../core/src/app.globals.d.ts\" />\nimport { Knex } from \"knex\";\n\ntype TFunction = (...args: any[]) => any\n\nexport interface TField {\n type: 'VAR_STRING' | 'BLOB' | 'DATETIME' | 'TIMESTAMP' | 'LONG' | 'JSON'\n length: number\n db: string\n table: string\n name: string\n string: TFunction,\n buffer: TFunction\n geometry: TFunction\n}\n\nexport interface TBaseConfig {\n client: 'mysql' | 'mysql2' | 'sqlite3' | 'oracle' | 'mariadb' | 'pg'\n connection: {\n typeCast?(field: TField, next: TFunction): any\n dateStrings?: boolean\n }\n pool?: {\n afterCreate: (connection: TConfig, callback: (val: any, con: any) => void) => Promise<any>\n } | undefined\n connections?: Record<string, TConfig>\n migrations?: {\n table: string\n path: string\n },\n factories?: {\n path: string\n },\n seeders?: {\n path: string\n },\n models?: {\n path: string\n }\n}\n\nexport type TConfig = TBaseConfig & ({\n client: 'pg'\n connection: Knex.PgConnectionConfig\n} | {\n client: 'oracle'\n connection: Knex.OracleDbConnectionConfig\n} | {\n client: 'mysql2'\n connection: Knex.MySql2ConnectionConfig\n} | {\n client: 'mysql'\n connection: Knex.MySqlConnectionConfig\n} | {\n client: 'sqlite3'\n connection: Knex.Sqlite3ConnectionConfig\n useNullAsDefault?: boolean\n} | {\n client: 'mariadb'\n connection: Knex.MariaSqlConnectionConfig\n useNullAsDefault?: boolean\n})\n\nexport const arquebusConfig = (config: any) => {\n return {\n sqlite: {\n client: config.connections.sqlite.driver,\n connection: <Knex.Sqlite3ConnectionConfig>{\n filename: database_path(config.connections.sqlite.database),\n debug: config.connections.sqlite.debug,\n flags: config.connections.sqlite.flags,\n options: config.connections.sqlite.options,\n expirationChecker: config.connections.sqlite.expirationChecker\n },\n useNullAsDefault: config.connections.sqlite.useNullAsDefault,\n },\n mysql: {\n client: config.connections.mysql.driver,\n connection: <Knex.MySql2ConnectionConfig>{\n host: config.connections.mysql.host ?? 'localhost',\n port: config.connections.mysql.port ?? 3306,\n user: config.connections.mysql.username ?? 'root',\n password: config.connections.mysql.password,\n database: config.connections.mysql.database,\n charset: config.connections.mysql.charset,\n socketPath: config.connections.mysql.unix_socket,\n localAddress: config.connections.mysql.url,\n },\n },\n mariadb: {\n client: config.connections.mariadb.driver,\n connection: <Knex.MariaSqlConnectionConfig>{\n host: config.connections.mariadb.host ?? 'localhost',\n port: config.connections.mariadb.port ?? 3306,\n user: config.connections.mariadb.username ?? 'root',\n password: config.connections.mariadb.password,\n database: config.connections.mariadb.database,\n charset: config.connections.mariadb.charset,\n socketPath: config.connections.mariadb.unix_socket,\n localAddress: config.connections.mariadb.url,\n expirationChecker: config.connections.mariadb.expirationChecker\n },\n },\n pgsql: {\n client: 'pg',\n connection: <Knex.PgConnectionConfig>{\n host: config.connections.pgsql.host ?? 'localhost',\n port: config.connections.pgsql.port ?? 3306,\n user: config.connections.pgsql.username ?? 'root',\n password: config.connections.pgsql.password,\n database: config.connections.pgsql.database,\n charset: config.connections.mysql.charset,\n connectionString: config.connections.pgsql.url,\n expirationChecker: config.connections.pgsql.expirationChecker\n },\n }\n } as unknown as TBaseConfig\n}\n","import { Model as BaseModel } from \"@h3ravel/arquebus\";\n\nexport class Model<M extends BaseModel = any> extends BaseModel {\n /**\n * Retrieve the model for a bound value.\n * \n * @param {any} value \n * @param {String|null} field \n * @returns \n */\n public resolveRouteBinding (value: any, field: undefined | string | null = null): Promise<M> {\n return this.newQuery().where(field ?? 'ids', value).firstOrFail()! as Promise<M>;\n }\n}\n","import { ServiceProvider } from '@h3ravel/core'\nimport { arquebus } from '@h3ravel/arquebus';\nimport { arquebusConfig } from '../Configuration';\n\n/**\n * Database connection, ORM, migrations.\n * \n * Register DatabaseManager and QueryBuilder if required.\n * Set up ORM models and relationships.\n * Register migration and seeder commands.\n * \n */\nexport class DatabaseServiceProvider extends ServiceProvider {\n public static priority = 994;\n\n register () {\n const config = this.app.make('config')\n\n const connection = Object.entries(arquebusConfig(config.get('database')))\n .find(([client]) => client === config.get('database.default'))\n ?.at(1)\n\n if (connection) {\n arquebus.addConnection(connection);\n }\n }\n}\n"],"mappings":";;;;AA+DA,MAAa,kBAAkB,WAAgB;AAC3C,QAAO;EACH,QAAQ;GACJ,QAAQ,OAAO,YAAY,OAAO;GAClC,YAA0C;IACtC,UAAU,cAAc,OAAO,YAAY,OAAO,SAAS;IAC3D,OAAO,OAAO,YAAY,OAAO;IACjC,OAAO,OAAO,YAAY,OAAO;IACjC,SAAS,OAAO,YAAY,OAAO;IACnC,mBAAmB,OAAO,YAAY,OAAO;IAChD;GACD,kBAAkB,OAAO,YAAY,OAAO;GAC/C;EACD,OAAO;GACH,QAAQ,OAAO,YAAY,MAAM;GACjC,YAAyC;IACrC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,YAAY;IAC3C,UAAU,OAAO,YAAY,MAAM;IACnC,UAAU,OAAO,YAAY,MAAM;IACnC,SAAS,OAAO,YAAY,MAAM;IAClC,YAAY,OAAO,YAAY,MAAM;IACrC,cAAc,OAAO,YAAY,MAAM;IAC1C;GACJ;EACD,SAAS;GACL,QAAQ,OAAO,YAAY,QAAQ;GACnC,YAA2C;IACvC,MAAM,OAAO,YAAY,QAAQ,QAAQ;IACzC,MAAM,OAAO,YAAY,QAAQ,QAAQ;IACzC,MAAM,OAAO,YAAY,QAAQ,YAAY;IAC7C,UAAU,OAAO,YAAY,QAAQ;IACrC,UAAU,OAAO,YAAY,QAAQ;IACrC,SAAS,OAAO,YAAY,QAAQ;IACpC,YAAY,OAAO,YAAY,QAAQ;IACvC,cAAc,OAAO,YAAY,QAAQ;IACzC,mBAAmB,OAAO,YAAY,QAAQ;IACjD;GACJ;EACD,OAAO;GACH,QAAQ;GACR,YAAqC;IACjC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,QAAQ;IACvC,MAAM,OAAO,YAAY,MAAM,YAAY;IAC3C,UAAU,OAAO,YAAY,MAAM;IACnC,UAAU,OAAO,YAAY,MAAM;IACnC,SAAS,OAAO,YAAY,MAAM;IAClC,kBAAkB,OAAO,YAAY,MAAM;IAC3C,mBAAmB,OAAO,YAAY,MAAM;IAC/C;GACJ;EACJ;;;;;AClHL,IAAa,QAAb,cAAsDA,QAAU;;;;;;;;CAQ5D,AAAO,oBAAqB,OAAY,QAAmC,MAAkB;AACzF,SAAO,KAAK,UAAU,CAAC,MAAM,SAAS,OAAO,MAAM,CAAC,aAAa;;;;;;;;;;;;;;ACCzE,IAAa,0BAAb,cAA6C,gBAAgB;CACzD,OAAc,WAAW;CAEzB,WAAY;EACR,MAAM,SAAS,KAAK,IAAI,KAAK,SAAS;EAEtC,MAAM,aAAa,OAAO,QAAQ,eAAe,OAAO,IAAI,WAAW,CAAC,CAAC,CACpE,MAAM,CAAC,YAAY,WAAW,OAAO,IAAI,mBAAmB,CAAC,EAC5D,GAAG,EAAE;AAEX,MAAI,WACA,UAAS,cAAc,WAAW"}
@@ -0,0 +1,21 @@
1
+ import { Migration } from '@h3ravel/arquebus'
2
+
3
+ export default class extends Migration {
4
+ /**
5
+ * Run the migrations.
6
+ *
7
+ * @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
8
+ */
9
+ async up(schema) {
10
+ //
11
+ }
12
+
13
+ /**
14
+ * Reverse the migrations.
15
+ *
16
+ * @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
17
+ */
18
+ async down(schema) {
19
+ //
20
+ }
21
+ };
@@ -0,0 +1,18 @@
1
+ import { Migration } from '@h3ravel/arquebus'
2
+ import { SchemaBuilder } from '@h3ravel/arquebus/types/query-builder';
3
+
4
+ export default class extends Migration {
5
+ /**
6
+ * Run the migrations.
7
+ */
8
+ async up (schema: SchemaBuilder) {
9
+ //
10
+ }
11
+
12
+ /**
13
+ * Reverse the migrations.
14
+ */
15
+ async down (schema: SchemaBuilder) {
16
+ //
17
+ }
18
+ };
@@ -0,0 +1,24 @@
1
+ import { Migration } from '@h3ravel/arquebus'
2
+
3
+ export default class extends Migration {
4
+ /**
5
+ * Run the migrations.
6
+ *
7
+ * @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
8
+ */
9
+ async up(schema) {
10
+ await schema.createTable('{{ table }}', (table) => {
11
+ table.increments('id');
12
+ table.timestamps();
13
+ });
14
+ }
15
+
16
+ /**
17
+ * Reverse the migrations.
18
+ *
19
+ * @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
20
+ */
21
+ async down(schema) {
22
+ await schema.dropTableIfExists('{{ table }}');
23
+ }
24
+ };
@@ -0,0 +1,21 @@
1
+ import { Migration } from '@h3ravel/arquebus'
2
+ import { SchemaBuilder } from '@h3ravel/arquebus/types/query-builder';
3
+
4
+ export default class extends Migration {
5
+ /**
6
+ * Run the migrations.
7
+ */
8
+ async up(schema: SchemaBuilder) {
9
+ await schema.createTable('{{ table }}', (table) => {
10
+ table.increments('id');
11
+ table.timestamps();
12
+ });
13
+ }
14
+
15
+ /**
16
+ * Reverse the migrations.
17
+ */
18
+ async down(schema: SchemaBuilder) {
19
+ await schema.dropTableIfExists('{{ table }}');
20
+ }
21
+ };
@@ -0,0 +1,25 @@
1
+ import { Migration } from '@h3ravel/arquebus'
2
+
3
+ export default class extends Migration {
4
+ /**
5
+ * Run the migrations.
6
+ *
7
+ * @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
8
+ */
9
+ async up(schema) {
10
+ await schema.table('{{ table }}', (table) => {
11
+ //
12
+ });
13
+ }
14
+
15
+ /**
16
+ * Reverse the migrations.
17
+ *
18
+ * @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
19
+ */
20
+ async down(schema) {
21
+ await schema.table('{{ table }}', (table) => {
22
+ //
23
+ });
24
+ }
25
+ };
@@ -0,0 +1,22 @@
1
+ import { Migration } from '@h3ravel/arquebus'
2
+ import { SchemaBuilder } from '@h3ravel/arquebus/types/query-builder';
3
+
4
+ export default class extends Migration {
5
+ /**
6
+ * Run the migrations.
7
+ */
8
+ async up(schema: SchemaBuilder) {
9
+ await schema.table('{{ table }}', (table) => {
10
+ //
11
+ });
12
+ }
13
+
14
+ /**
15
+ * Reverse the migrations.
16
+ */
17
+ async down(schema: SchemaBuilder) {
18
+ await schema.table('{{ table }}', (table) => {
19
+ //
20
+ });
21
+ }
22
+ };
@@ -0,0 +1,5 @@
1
+ import { Model } from '@h3ravel/database'
2
+
3
+ export default class {{ name }} extends Model {
4
+ //
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Model } from '@h3ravel/database'
2
+
3
+ export default class {{ name }} extends Model {
4
+ //
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/database",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "Modeling data and migration system for H3ravel.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,15 +35,20 @@
35
35
  "typescript",
36
36
  "laravel"
37
37
  ],
38
+ "dependencies": {
39
+ "@h3ravel/arquebus": "^0.4.0",
40
+ "sqlite3": "^5.1.7"
41
+ },
38
42
  "peerDependencies": {
39
- "@h3ravel/core": "^1.7.0"
43
+ "@h3ravel/core": "^1.8.0",
44
+ "@h3ravel/support": "^0.10.0"
40
45
  },
41
46
  "devDependencies": {
42
- "typescript": "^5.4.0"
47
+ "typescript": "^5.9.2"
43
48
  },
44
49
  "scripts": {
45
50
  "barrel": "barrelsby --directory src --delete --singleQuotes",
46
- "build": "tsup",
51
+ "build": "tsdown --config-loader unconfig",
47
52
  "dev": "tsx watch src/index.ts",
48
53
  "start": "node dist/index.js",
49
54
  "lint": "eslint . --ext .ts",