@arikajs/database 0.0.1
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/LICENSE +21 -0
- package/README.md +333 -0
- package/dist/Connections/MySQLConnection.d.ts +39 -0
- package/dist/Connections/MySQLConnection.d.ts.map +1 -0
- package/dist/Connections/MySQLConnection.js +91 -0
- package/dist/Connections/MySQLConnection.js.map +1 -0
- package/dist/Connections/PostgreSQLConnection.d.ts +39 -0
- package/dist/Connections/PostgreSQLConnection.d.ts.map +1 -0
- package/dist/Connections/PostgreSQLConnection.js +85 -0
- package/dist/Connections/PostgreSQLConnection.js.map +1 -0
- package/dist/Connections/SQLiteConnection.d.ts +51 -0
- package/dist/Connections/SQLiteConnection.d.ts.map +1 -0
- package/dist/Connections/SQLiteConnection.js +111 -0
- package/dist/Connections/SQLiteConnection.js.map +1 -0
- package/dist/Contracts/Database.d.ts +131 -0
- package/dist/Contracts/Database.d.ts.map +1 -0
- package/dist/Contracts/Database.js +3 -0
- package/dist/Contracts/Database.js.map +1 -0
- package/dist/Contracts/Schema.d.ts +124 -0
- package/dist/Contracts/Schema.d.ts.map +1 -0
- package/dist/Contracts/Schema.js +3 -0
- package/dist/Contracts/Schema.js.map +1 -0
- package/dist/Database.d.ts +38 -0
- package/dist/Database.d.ts.map +1 -0
- package/dist/Database.js +55 -0
- package/dist/Database.js.map +1 -0
- package/dist/DatabaseManager.d.ts +36 -0
- package/dist/DatabaseManager.d.ts.map +1 -0
- package/dist/DatabaseManager.js +126 -0
- package/dist/DatabaseManager.js.map +1 -0
- package/dist/Migrations/Migration.d.ts +17 -0
- package/dist/Migrations/Migration.d.ts.map +1 -0
- package/dist/Migrations/Migration.js +10 -0
- package/dist/Migrations/Migration.js.map +1 -0
- package/dist/Migrations/Migrator.d.ts +51 -0
- package/dist/Migrations/Migrator.d.ts.map +1 -0
- package/dist/Migrations/Migrator.js +166 -0
- package/dist/Migrations/Migrator.js.map +1 -0
- package/dist/Model/Model.d.ts +309 -0
- package/dist/Model/Model.d.ts.map +1 -0
- package/dist/Model/Model.js +607 -0
- package/dist/Model/Model.js.map +1 -0
- package/dist/Model/Relations.d.ts +53 -0
- package/dist/Model/Relations.d.ts.map +1 -0
- package/dist/Model/Relations.js +124 -0
- package/dist/Model/Relations.js.map +1 -0
- package/dist/Model/SoftDeletes.d.ts +24 -0
- package/dist/Model/SoftDeletes.d.ts.map +1 -0
- package/dist/Model/SoftDeletes.js +95 -0
- package/dist/Model/SoftDeletes.js.map +1 -0
- package/dist/Query/QueryBuilder.d.ts +94 -0
- package/dist/Query/QueryBuilder.d.ts.map +1 -0
- package/dist/Query/QueryBuilder.js +276 -0
- package/dist/Query/QueryBuilder.js.map +1 -0
- package/dist/Schema/Grammars/Grammar.d.ts +27 -0
- package/dist/Schema/Grammars/Grammar.d.ts.map +1 -0
- package/dist/Schema/Grammars/Grammar.js +25 -0
- package/dist/Schema/Grammars/Grammar.js.map +1 -0
- package/dist/Schema/Grammars/MySQLGrammar.d.ts +13 -0
- package/dist/Schema/Grammars/MySQLGrammar.d.ts.map +1 -0
- package/dist/Schema/Grammars/MySQLGrammar.js +78 -0
- package/dist/Schema/Grammars/MySQLGrammar.js.map +1 -0
- package/dist/Schema/Grammars/PostgreSQLGrammar.d.ts +13 -0
- package/dist/Schema/Grammars/PostgreSQLGrammar.d.ts.map +1 -0
- package/dist/Schema/Grammars/PostgreSQLGrammar.js +57 -0
- package/dist/Schema/Grammars/PostgreSQLGrammar.js.map +1 -0
- package/dist/Schema/Grammars/SQLiteGrammar.d.ts +13 -0
- package/dist/Schema/Grammars/SQLiteGrammar.d.ts.map +1 -0
- package/dist/Schema/Grammars/SQLiteGrammar.js +53 -0
- package/dist/Schema/Grammars/SQLiteGrammar.js.map +1 -0
- package/dist/Schema/Schema.d.ts +120 -0
- package/dist/Schema/Schema.d.ts.map +1 -0
- package/dist/Schema/Schema.js +226 -0
- package/dist/Schema/Schema.js.map +1 -0
- package/dist/Schema/SchemaBuilder.d.ts +24 -0
- package/dist/Schema/SchemaBuilder.d.ts.map +1 -0
- package/dist/Schema/SchemaBuilder.js +49 -0
- package/dist/Schema/SchemaBuilder.js.map +1 -0
- package/dist/Seeders/SeedRunner.d.ts +22 -0
- package/dist/Seeders/SeedRunner.d.ts.map +1 -0
- package/dist/Seeders/SeedRunner.js +72 -0
- package/dist/Seeders/SeedRunner.js.map +1 -0
- package/dist/Seeders/Seeder.d.ts +11 -0
- package/dist/Seeders/Seeder.d.ts.map +1 -0
- package/dist/Seeders/Seeder.js +10 -0
- package/dist/Seeders/Seeder.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SQLiteConnection = void 0;
|
|
7
|
+
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
8
|
+
/**
|
|
9
|
+
* SQLite database connection
|
|
10
|
+
*/
|
|
11
|
+
class SQLiteConnection {
|
|
12
|
+
constructor(config) {
|
|
13
|
+
this.db = null;
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Connect to the database
|
|
18
|
+
*/
|
|
19
|
+
async connect() {
|
|
20
|
+
if (this.db) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.db = new better_sqlite3_1.default(this.config.database || ':memory:');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Disconnect from the database
|
|
27
|
+
*/
|
|
28
|
+
async disconnect() {
|
|
29
|
+
if (this.db) {
|
|
30
|
+
this.db.close();
|
|
31
|
+
this.db = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Execute a query
|
|
36
|
+
*/
|
|
37
|
+
async query(sql, bindings = []) {
|
|
38
|
+
if (!this.db) {
|
|
39
|
+
await this.connect();
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const stmt = this.db.prepare(sql);
|
|
43
|
+
// Check if it's a SELECT query
|
|
44
|
+
if (sql.trim().toLowerCase().startsWith('select')) {
|
|
45
|
+
return stmt.all(...bindings);
|
|
46
|
+
}
|
|
47
|
+
// For INSERT, UPDATE, DELETE
|
|
48
|
+
const info = stmt.run(...bindings);
|
|
49
|
+
return [{ affectedRows: info.changes, insertId: info.lastInsertRowid }];
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new Error(`SQLite query failed: ${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Execute a raw query
|
|
57
|
+
*/
|
|
58
|
+
async raw(sql) {
|
|
59
|
+
if (!this.db) {
|
|
60
|
+
await this.connect();
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return this.db.exec(sql);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new Error(`SQLite raw query failed: ${error.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the underlying database instance
|
|
71
|
+
*/
|
|
72
|
+
getDriver() {
|
|
73
|
+
if (!this.db) {
|
|
74
|
+
throw new Error('Database not connected');
|
|
75
|
+
}
|
|
76
|
+
return this.db;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Close the connection
|
|
80
|
+
*/
|
|
81
|
+
async close() {
|
|
82
|
+
await this.disconnect();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Begin a transaction
|
|
86
|
+
*/
|
|
87
|
+
async beginTransaction() {
|
|
88
|
+
await this.query('BEGIN TRANSACTION');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Commit a transaction
|
|
92
|
+
*/
|
|
93
|
+
async commit() {
|
|
94
|
+
await this.query('COMMIT');
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Rollback a transaction
|
|
98
|
+
*/
|
|
99
|
+
async rollback() {
|
|
100
|
+
await this.query('ROLLBACK');
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the schema grammar for this connection
|
|
104
|
+
*/
|
|
105
|
+
getSchemaGrammar() {
|
|
106
|
+
const { SQLiteGrammar } = require('../Schema/Grammars/SQLiteGrammar');
|
|
107
|
+
return new SQLiteGrammar();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.SQLiteConnection = SQLiteConnection;
|
|
111
|
+
//# sourceMappingURL=SQLiteConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQLiteConnection.js","sourceRoot":"","sources":["../../src/Connections/SQLiteConnection.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAsC;AAGtC;;GAEG;AACH,MAAa,gBAAgB;IAIzB,YAAY,MAAwB;QAH5B,OAAE,GAA6B,IAAI,CAAC;QAIxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACT,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACV,OAAO;QACX,CAAC;QAED,IAAI,CAAC,EAAE,GAAG,IAAI,wBAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,UAAU,CAAC,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACZ,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACV,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACnB,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK,CAAC,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CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC,EAAE,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACP,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB;QAClB,MAAM,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACR,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACV,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;QACtE,OAAO,IAAI,aAAa,EAAE,CAAC;IAC/B,CAAC;CACJ;AAjHD,4CAiHC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database connection configuration
|
|
3
|
+
*/
|
|
4
|
+
export interface ConnectionConfig {
|
|
5
|
+
driver: 'mysql' | 'pgsql' | 'sqlite';
|
|
6
|
+
host?: string;
|
|
7
|
+
port?: number;
|
|
8
|
+
database: string;
|
|
9
|
+
username?: string;
|
|
10
|
+
password?: string;
|
|
11
|
+
charset?: string;
|
|
12
|
+
timezone?: string;
|
|
13
|
+
pool?: {
|
|
14
|
+
min?: number;
|
|
15
|
+
max?: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Database configuration with multiple connections
|
|
20
|
+
*/
|
|
21
|
+
export interface DatabaseConfig {
|
|
22
|
+
default: string;
|
|
23
|
+
connections: Record<string, ConnectionConfig>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Database connection interface
|
|
27
|
+
*/
|
|
28
|
+
export interface Connection {
|
|
29
|
+
/**
|
|
30
|
+
* Execute a raw SQL query
|
|
31
|
+
*/
|
|
32
|
+
query(sql: string, bindings?: any[]): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Begin a transaction
|
|
35
|
+
*/
|
|
36
|
+
beginTransaction(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Commit a transaction
|
|
39
|
+
*/
|
|
40
|
+
commit(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Rollback a transaction
|
|
43
|
+
*/
|
|
44
|
+
rollback(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Close the connection
|
|
47
|
+
*/
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Get the underlying driver connection
|
|
51
|
+
*/
|
|
52
|
+
getDriver(): any;
|
|
53
|
+
/**
|
|
54
|
+
* Get the schema grammar for this connection
|
|
55
|
+
*/
|
|
56
|
+
getSchemaGrammar(): any;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Query builder interface
|
|
60
|
+
*/
|
|
61
|
+
export interface QueryBuilder {
|
|
62
|
+
/**
|
|
63
|
+
* Set the table for the query
|
|
64
|
+
*/
|
|
65
|
+
table(table: string): this;
|
|
66
|
+
/**
|
|
67
|
+
* Add a where clause
|
|
68
|
+
*/
|
|
69
|
+
where(column: string, operator: any, value?: any): this;
|
|
70
|
+
/**
|
|
71
|
+
* Add an OR where clause
|
|
72
|
+
*/
|
|
73
|
+
orWhere(column: string, operator: any, value?: any): this;
|
|
74
|
+
/**
|
|
75
|
+
* Add a where in clause
|
|
76
|
+
*/
|
|
77
|
+
whereIn(column: string, values: any[]): this;
|
|
78
|
+
/**
|
|
79
|
+
* Add a where not in clause
|
|
80
|
+
*/
|
|
81
|
+
whereNotIn(column: string, values: any[]): this;
|
|
82
|
+
/**
|
|
83
|
+
* Add a where null clause
|
|
84
|
+
*/
|
|
85
|
+
whereNull(column: string): this;
|
|
86
|
+
/**
|
|
87
|
+
* Add a where not null clause
|
|
88
|
+
*/
|
|
89
|
+
whereNotNull(column: string): this;
|
|
90
|
+
/**
|
|
91
|
+
* Add a select clause
|
|
92
|
+
*/
|
|
93
|
+
select(...columns: string[]): this;
|
|
94
|
+
/**
|
|
95
|
+
* Add an order by clause
|
|
96
|
+
*/
|
|
97
|
+
orderBy(column: string, direction?: 'asc' | 'desc'): this;
|
|
98
|
+
/**
|
|
99
|
+
* Add a limit clause
|
|
100
|
+
*/
|
|
101
|
+
limit(limit: number): this;
|
|
102
|
+
/**
|
|
103
|
+
* Add an offset clause
|
|
104
|
+
*/
|
|
105
|
+
offset(offset: number): this;
|
|
106
|
+
/**
|
|
107
|
+
* Execute the query and get all results
|
|
108
|
+
*/
|
|
109
|
+
get(): Promise<any[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Execute the query and get the first result
|
|
112
|
+
*/
|
|
113
|
+
first(): Promise<any | null>;
|
|
114
|
+
/**
|
|
115
|
+
* Insert a record
|
|
116
|
+
*/
|
|
117
|
+
insert(data: Record<string, any>): Promise<any>;
|
|
118
|
+
/**
|
|
119
|
+
* Update records
|
|
120
|
+
*/
|
|
121
|
+
update(data: Record<string, any>): Promise<number>;
|
|
122
|
+
/**
|
|
123
|
+
* Delete records
|
|
124
|
+
*/
|
|
125
|
+
delete(): Promise<number>;
|
|
126
|
+
/**
|
|
127
|
+
* Get the count of records
|
|
128
|
+
*/
|
|
129
|
+
count(column?: string): Promise<number>;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=Database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../../src/Contracts/Database.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;I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0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.js","sourceRoot":"","sources":["../../src/Contracts/Database.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column definition interface
|
|
3
|
+
*/
|
|
4
|
+
export interface ColumnDefinition {
|
|
5
|
+
/**
|
|
6
|
+
* Make the column nullable
|
|
7
|
+
*/
|
|
8
|
+
nullable(): this;
|
|
9
|
+
/**
|
|
10
|
+
* Set a default value
|
|
11
|
+
*/
|
|
12
|
+
default(value: any): this;
|
|
13
|
+
/**
|
|
14
|
+
* Make the column unique
|
|
15
|
+
*/
|
|
16
|
+
unique(): this;
|
|
17
|
+
/**
|
|
18
|
+
* Make the column unsigned (for numeric types)
|
|
19
|
+
*/
|
|
20
|
+
unsigned(): this;
|
|
21
|
+
/**
|
|
22
|
+
* Add a comment to the column
|
|
23
|
+
*/
|
|
24
|
+
comment(comment: string): this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Table blueprint for schema building
|
|
28
|
+
*/
|
|
29
|
+
export interface Blueprint {
|
|
30
|
+
/**
|
|
31
|
+
* Create an auto-incrementing ID column
|
|
32
|
+
*/
|
|
33
|
+
id(name?: string): ColumnDefinition;
|
|
34
|
+
/**
|
|
35
|
+
* Create a string column
|
|
36
|
+
*/
|
|
37
|
+
string(name: string, length?: number): ColumnDefinition;
|
|
38
|
+
/**
|
|
39
|
+
* Create an integer column
|
|
40
|
+
*/
|
|
41
|
+
integer(name: string): ColumnDefinition;
|
|
42
|
+
/**
|
|
43
|
+
* Create a big integer column
|
|
44
|
+
*/
|
|
45
|
+
bigInteger(name: string): ColumnDefinition;
|
|
46
|
+
/**
|
|
47
|
+
* Create a boolean column
|
|
48
|
+
*/
|
|
49
|
+
boolean(name: string): ColumnDefinition;
|
|
50
|
+
/**
|
|
51
|
+
* Create a text column
|
|
52
|
+
*/
|
|
53
|
+
text(name: string): ColumnDefinition;
|
|
54
|
+
/**
|
|
55
|
+
* Create a timestamp column
|
|
56
|
+
*/
|
|
57
|
+
timestamp(name: string): ColumnDefinition;
|
|
58
|
+
/**
|
|
59
|
+
* Create created_at and updated_at timestamp columns
|
|
60
|
+
*/
|
|
61
|
+
timestamps(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Create a decimal column
|
|
64
|
+
*/
|
|
65
|
+
decimal(name: string, precision?: number, scale?: number): ColumnDefinition;
|
|
66
|
+
/**
|
|
67
|
+
* Create a date column
|
|
68
|
+
*/
|
|
69
|
+
date(name: string): ColumnDefinition;
|
|
70
|
+
/**
|
|
71
|
+
* Create a datetime column
|
|
72
|
+
*/
|
|
73
|
+
datetime(name: string): ColumnDefinition;
|
|
74
|
+
/**
|
|
75
|
+
* Create a JSON column
|
|
76
|
+
*/
|
|
77
|
+
json(name: string): ColumnDefinition;
|
|
78
|
+
/**
|
|
79
|
+
* Add a foreign key constraint
|
|
80
|
+
*/
|
|
81
|
+
foreign(column: string): ForeignKeyDefinition;
|
|
82
|
+
/**
|
|
83
|
+
* Add an index
|
|
84
|
+
*/
|
|
85
|
+
index(columns: string | string[], name?: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* Add a unique index
|
|
88
|
+
*/
|
|
89
|
+
unique(columns: string | string[], name?: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Drop a column
|
|
92
|
+
*/
|
|
93
|
+
dropColumn(name: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Drop an index
|
|
96
|
+
*/
|
|
97
|
+
dropIndex(name: string): void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Foreign key definition
|
|
101
|
+
*/
|
|
102
|
+
export interface ForeignKeyDefinition {
|
|
103
|
+
/**
|
|
104
|
+
* Set the referenced table
|
|
105
|
+
*/
|
|
106
|
+
references(column: string): this;
|
|
107
|
+
/**
|
|
108
|
+
* Set the referenced table
|
|
109
|
+
*/
|
|
110
|
+
on(table: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Set the on delete action
|
|
113
|
+
*/
|
|
114
|
+
onDelete(action: 'cascade' | 'set null' | 'restrict' | 'no action'): this;
|
|
115
|
+
/**
|
|
116
|
+
* Set the on update action
|
|
117
|
+
*/
|
|
118
|
+
onUpdate(action: 'cascade' | 'set null' | 'restrict' | 'no action'): this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Schema builder callback
|
|
122
|
+
*/
|
|
123
|
+
export type SchemaCallback = (table: Blueprint) => void;
|
|
124
|
+
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/Contracts/Schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,QAAQ,IAAI,IAAI,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IAE1B;;OAEG;IACH,MAAM,IAAI,IAAI,CAAC;IAEf;;OAEG;IACH,QAAQ,IAAI,IAAI,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAEpC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAExD;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAExC;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAE3C;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAExC;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAg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AU,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,CAAC;CAC7E;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Schema.js","sourceRoot":"","sources":["../../src/Contracts/Schema.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DatabaseManager } from './DatabaseManager';
|
|
2
|
+
import { QueryBuilder } from './Query/QueryBuilder';
|
|
3
|
+
import { SchemaBuilder } from './Schema/SchemaBuilder';
|
|
4
|
+
/**
|
|
5
|
+
* Database facade - static interface to the database manager
|
|
6
|
+
*/
|
|
7
|
+
export declare class Database {
|
|
8
|
+
private static manager;
|
|
9
|
+
/**
|
|
10
|
+
* Set the database manager instance
|
|
11
|
+
*/
|
|
12
|
+
static setManager(manager: DatabaseManager): void;
|
|
13
|
+
/**
|
|
14
|
+
* Get the database manager instance
|
|
15
|
+
*/
|
|
16
|
+
static getManager(): DatabaseManager;
|
|
17
|
+
/**
|
|
18
|
+
* Create a new query builder for a table
|
|
19
|
+
*/
|
|
20
|
+
static table(tableName: string, connectionName?: string): QueryBuilder;
|
|
21
|
+
/**
|
|
22
|
+
* Get a schema builder instance
|
|
23
|
+
*/
|
|
24
|
+
static schema(connectionName?: string): SchemaBuilder;
|
|
25
|
+
/**
|
|
26
|
+
* Execute a transaction
|
|
27
|
+
*/
|
|
28
|
+
static transaction<T>(callback: (trx: DatabaseManager) => Promise<T>, connectionName?: string): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Get a connection by name
|
|
31
|
+
*/
|
|
32
|
+
static connection(name?: string): import(".").Connection | Promise<import(".").Connection>;
|
|
33
|
+
/**
|
|
34
|
+
* Close all connections
|
|
35
|
+
*/
|
|
36
|
+
static closeAll(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=Database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.d.ts","sourceRoot":"","sources":["../src/Database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AACH,qBAAa,QAAQ;IACjB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAkB;IAExC;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAIjD;;OAEG;IACH,MAAM,CAAC,UAAU,IAAI,eAAe;IAOpC;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,YAAY;IAItE;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,aAAa;IAIrD;;OAEG;WACU,WAAW,CAAC,CAAC,EACtB,QAAQ,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9C,cAAc,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,CAAC,CAAC;IAIb;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM;IAI/B;;OAEG;WACU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGzC"}
|
package/dist/Database.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Database = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Database facade - static interface to the database manager
|
|
6
|
+
*/
|
|
7
|
+
class Database {
|
|
8
|
+
/**
|
|
9
|
+
* Set the database manager instance
|
|
10
|
+
*/
|
|
11
|
+
static setManager(manager) {
|
|
12
|
+
Database.manager = manager;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the database manager instance
|
|
16
|
+
*/
|
|
17
|
+
static getManager() {
|
|
18
|
+
if (!Database.manager) {
|
|
19
|
+
throw new Error('DatabaseManager not initialized. Call Database.setManager() first.');
|
|
20
|
+
}
|
|
21
|
+
return Database.manager;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a new query builder for a table
|
|
25
|
+
*/
|
|
26
|
+
static table(tableName, connectionName) {
|
|
27
|
+
return Database.getManager().table(tableName, connectionName);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get a schema builder instance
|
|
31
|
+
*/
|
|
32
|
+
static schema(connectionName) {
|
|
33
|
+
return Database.getManager().schema(connectionName);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Execute a transaction
|
|
37
|
+
*/
|
|
38
|
+
static async transaction(callback, connectionName) {
|
|
39
|
+
return await Database.getManager().transaction(callback, connectionName);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get a connection by name
|
|
43
|
+
*/
|
|
44
|
+
static connection(name) {
|
|
45
|
+
return Database.getManager().connection(name);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Close all connections
|
|
49
|
+
*/
|
|
50
|
+
static async closeAll() {
|
|
51
|
+
return Database.getManager().closeAll();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.Database = Database;
|
|
55
|
+
//# sourceMappingURL=Database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.js","sourceRoot":"","sources":["../src/Database.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACH,MAAa,QAAQ;IAGjB;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,OAAwB;QACtC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU;QACb,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;QAC1F,CAAC;QACD,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,SAAiB,EAAE,cAAuB;QACnD,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,cAAuB;QACjC,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CACpB,QAA8C,EAC9C,cAAuB;QAEvB,OAAO,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC7E,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,IAAa;QAC3B,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,QAAQ;QACjB,OAAO,QAAQ,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC5C,CAAC;CACJ;AAzDD,4BAyDC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Connection, DatabaseConfig } from './Contracts/Database';
|
|
2
|
+
import { QueryBuilder } from './Query/QueryBuilder';
|
|
3
|
+
import { SchemaBuilder } from './Schema/SchemaBuilder';
|
|
4
|
+
/**
|
|
5
|
+
* Database manager - handles connections and query builders
|
|
6
|
+
*/
|
|
7
|
+
export declare class DatabaseManager {
|
|
8
|
+
private connections;
|
|
9
|
+
private config;
|
|
10
|
+
constructor(config: DatabaseConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Get a connection by name
|
|
13
|
+
*/
|
|
14
|
+
connection(name?: string): Connection | Promise<Connection>;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new query builder
|
|
17
|
+
*/
|
|
18
|
+
table(tableName: string, connectionName?: string): QueryBuilder;
|
|
19
|
+
/**
|
|
20
|
+
* Get a schema builder instance
|
|
21
|
+
*/
|
|
22
|
+
schema(connectionName?: string): SchemaBuilder;
|
|
23
|
+
/**
|
|
24
|
+
* Execute a transaction
|
|
25
|
+
*/
|
|
26
|
+
transaction<T>(callback: (trx: DatabaseManager) => Promise<T>, connectionName?: string): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Close all connections
|
|
29
|
+
*/
|
|
30
|
+
closeAll(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Create a connection based on driver type
|
|
33
|
+
*/
|
|
34
|
+
private createConnection;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=DatabaseManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseManager.d.ts","sourceRoot":"","sources":["../src/DatabaseManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,WAAW,CAAsC;IACzD,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;IAIlC;;OAEG;IACH,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAoB3D;;OAEG;IACH,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,YAAY;IAK/D;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,aAAa;IAK9C;;OAEG;IACG,WAAW,CAAC,CAAC,EACf,QAAQ,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9C,cAAc,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,CAAC,CAAC;IAeb;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B;;OAEG;YACW,gBAAgB;CAkBjC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DatabaseManager = void 0;
|
|
37
|
+
const QueryBuilder_1 = require("./Query/QueryBuilder");
|
|
38
|
+
const SchemaBuilder_1 = require("./Schema/SchemaBuilder");
|
|
39
|
+
/**
|
|
40
|
+
* Database manager - handles connections and query builders
|
|
41
|
+
*/
|
|
42
|
+
class DatabaseManager {
|
|
43
|
+
constructor(config) {
|
|
44
|
+
this.connections = new Map();
|
|
45
|
+
this.config = config;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get a connection by name
|
|
49
|
+
*/
|
|
50
|
+
connection(name) {
|
|
51
|
+
const connectionName = name || this.config.default;
|
|
52
|
+
if (this.connections.has(connectionName)) {
|
|
53
|
+
return this.connections.get(connectionName);
|
|
54
|
+
}
|
|
55
|
+
const connectionConfig = this.config.connections[connectionName];
|
|
56
|
+
if (!connectionConfig) {
|
|
57
|
+
throw new Error(`Connection "${connectionName}" not configured`);
|
|
58
|
+
}
|
|
59
|
+
const connectionPromise = this.createConnection(connectionConfig).then(connection => {
|
|
60
|
+
this.connections.set(connectionName, connection);
|
|
61
|
+
return connection;
|
|
62
|
+
});
|
|
63
|
+
return connectionPromise;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a new query builder
|
|
67
|
+
*/
|
|
68
|
+
table(tableName, connectionName) {
|
|
69
|
+
const connection = this.connection(connectionName);
|
|
70
|
+
return new QueryBuilder_1.QueryBuilder(connection).table(tableName);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get a schema builder instance
|
|
74
|
+
*/
|
|
75
|
+
schema(connectionName) {
|
|
76
|
+
const connection = this.connection(connectionName);
|
|
77
|
+
return new SchemaBuilder_1.SchemaBuilder(connection);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Execute a transaction
|
|
81
|
+
*/
|
|
82
|
+
async transaction(callback, connectionName) {
|
|
83
|
+
const connection = await this.connection(connectionName);
|
|
84
|
+
await connection.beginTransaction();
|
|
85
|
+
try {
|
|
86
|
+
const result = await callback(this);
|
|
87
|
+
await connection.commit();
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
await connection.rollback();
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Close all connections
|
|
97
|
+
*/
|
|
98
|
+
async closeAll() {
|
|
99
|
+
const promises = Array.from(this.connections.values()).map(conn => conn.close());
|
|
100
|
+
await Promise.all(promises);
|
|
101
|
+
this.connections.clear();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a connection based on driver type
|
|
105
|
+
*/
|
|
106
|
+
async createConnection(config) {
|
|
107
|
+
switch (config.driver) {
|
|
108
|
+
case 'mysql': {
|
|
109
|
+
const { MySQLConnection } = await Promise.resolve().then(() => __importStar(require('./Connections/MySQLConnection')));
|
|
110
|
+
return new MySQLConnection(config);
|
|
111
|
+
}
|
|
112
|
+
case 'pgsql': {
|
|
113
|
+
const { PostgreSQLConnection } = await Promise.resolve().then(() => __importStar(require('./Connections/PostgreSQLConnection')));
|
|
114
|
+
return new PostgreSQLConnection(config);
|
|
115
|
+
}
|
|
116
|
+
case 'sqlite': {
|
|
117
|
+
const { SQLiteConnection } = await Promise.resolve().then(() => __importStar(require('./Connections/SQLiteConnection')));
|
|
118
|
+
return new SQLiteConnection(config);
|
|
119
|
+
}
|
|
120
|
+
default:
|
|
121
|
+
throw new Error(`Unsupported database driver: ${config.driver}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.DatabaseManager = DatabaseManager;
|
|
126
|
+
//# sour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