@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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +333 -0
  3. package/dist/Connections/MySQLConnection.d.ts +39 -0
  4. package/dist/Connections/MySQLConnection.d.ts.map +1 -0
  5. package/dist/Connections/MySQLConnection.js +91 -0
  6. package/dist/Connections/MySQLConnection.js.map +1 -0
  7. package/dist/Connections/PostgreSQLConnection.d.ts +39 -0
  8. package/dist/Connections/PostgreSQLConnection.d.ts.map +1 -0
  9. package/dist/Connections/PostgreSQLConnection.js +85 -0
  10. package/dist/Connections/PostgreSQLConnection.js.map +1 -0
  11. package/dist/Connections/SQLiteConnection.d.ts +51 -0
  12. package/dist/Connections/SQLiteConnection.d.ts.map +1 -0
  13. package/dist/Connections/SQLiteConnection.js +111 -0
  14. package/dist/Connections/SQLiteConnection.js.map +1 -0
  15. package/dist/Contracts/Database.d.ts +131 -0
  16. package/dist/Contracts/Database.d.ts.map +1 -0
  17. package/dist/Contracts/Database.js +3 -0
  18. package/dist/Contracts/Database.js.map +1 -0
  19. package/dist/Contracts/Schema.d.ts +124 -0
  20. package/dist/Contracts/Schema.d.ts.map +1 -0
  21. package/dist/Contracts/Schema.js +3 -0
  22. package/dist/Contracts/Schema.js.map +1 -0
  23. package/dist/Database.d.ts +38 -0
  24. package/dist/Database.d.ts.map +1 -0
  25. package/dist/Database.js +55 -0
  26. package/dist/Database.js.map +1 -0
  27. package/dist/DatabaseManager.d.ts +36 -0
  28. package/dist/DatabaseManager.d.ts.map +1 -0
  29. package/dist/DatabaseManager.js +126 -0
  30. package/dist/DatabaseManager.js.map +1 -0
  31. package/dist/Migrations/Migration.d.ts +17 -0
  32. package/dist/Migrations/Migration.d.ts.map +1 -0
  33. package/dist/Migrations/Migration.js +10 -0
  34. package/dist/Migrations/Migration.js.map +1 -0
  35. package/dist/Migrations/Migrator.d.ts +51 -0
  36. package/dist/Migrations/Migrator.d.ts.map +1 -0
  37. package/dist/Migrations/Migrator.js +166 -0
  38. package/dist/Migrations/Migrator.js.map +1 -0
  39. package/dist/Model/Model.d.ts +309 -0
  40. package/dist/Model/Model.d.ts.map +1 -0
  41. package/dist/Model/Model.js +607 -0
  42. package/dist/Model/Model.js.map +1 -0
  43. package/dist/Model/Relations.d.ts +53 -0
  44. package/dist/Model/Relations.d.ts.map +1 -0
  45. package/dist/Model/Relations.js +124 -0
  46. package/dist/Model/Relations.js.map +1 -0
  47. package/dist/Model/SoftDeletes.d.ts +24 -0
  48. package/dist/Model/SoftDeletes.d.ts.map +1 -0
  49. package/dist/Model/SoftDeletes.js +95 -0
  50. package/dist/Model/SoftDeletes.js.map +1 -0
  51. package/dist/Query/QueryBuilder.d.ts +94 -0
  52. package/dist/Query/QueryBuilder.d.ts.map +1 -0
  53. package/dist/Query/QueryBuilder.js +276 -0
  54. package/dist/Query/QueryBuilder.js.map +1 -0
  55. package/dist/Schema/Grammars/Grammar.d.ts +27 -0
  56. package/dist/Schema/Grammars/Grammar.d.ts.map +1 -0
  57. package/dist/Schema/Grammars/Grammar.js +25 -0
  58. package/dist/Schema/Grammars/Grammar.js.map +1 -0
  59. package/dist/Schema/Grammars/MySQLGrammar.d.ts +13 -0
  60. package/dist/Schema/Grammars/MySQLGrammar.d.ts.map +1 -0
  61. package/dist/Schema/Grammars/MySQLGrammar.js +78 -0
  62. package/dist/Schema/Grammars/MySQLGrammar.js.map +1 -0
  63. package/dist/Schema/Grammars/PostgreSQLGrammar.d.ts +13 -0
  64. package/dist/Schema/Grammars/PostgreSQLGrammar.d.ts.map +1 -0
  65. package/dist/Schema/Grammars/PostgreSQLGrammar.js +57 -0
  66. package/dist/Schema/Grammars/PostgreSQLGrammar.js.map +1 -0
  67. package/dist/Schema/Grammars/SQLiteGrammar.d.ts +13 -0
  68. package/dist/Schema/Grammars/SQLiteGrammar.d.ts.map +1 -0
  69. package/dist/Schema/Grammars/SQLiteGrammar.js +53 -0
  70. package/dist/Schema/Grammars/SQLiteGrammar.js.map +1 -0
  71. package/dist/Schema/Schema.d.ts +120 -0
  72. package/dist/Schema/Schema.d.ts.map +1 -0
  73. package/dist/Schema/Schema.js +226 -0
  74. package/dist/Schema/Schema.js.map +1 -0
  75. package/dist/Schema/SchemaBuilder.d.ts +24 -0
  76. package/dist/Schema/SchemaBuilder.d.ts.map +1 -0
  77. package/dist/Schema/SchemaBuilder.js +49 -0
  78. package/dist/Schema/SchemaBuilder.js.map +1 -0
  79. package/dist/Seeders/SeedRunner.d.ts +22 -0
  80. package/dist/Seeders/SeedRunner.d.ts.map +1 -0
  81. package/dist/Seeders/SeedRunner.js +72 -0
  82. package/dist/Seeders/SeedRunner.js.map +1 -0
  83. package/dist/Seeders/Seeder.d.ts +11 -0
  84. package/dist/Seeders/Seeder.d.ts.map +1 -0
  85. package/dist/Seeders/Seeder.js +10 -0
  86. package/dist/Seeders/Seeder.js.map +1 -0
  87. package/dist/index.d.ts +19 -0
  88. package/dist/index.d.ts.map +1 -0
  89. package/dist/index.js +52 -0
  90. package/dist/index.js.map +1 -0
  91. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ArikaJs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,333 @@
1
+ # @arikajs/database
2
+
3
+ **@arikajs/database** is the official database layer for the ArikaJS framework.
4
+ It provides a powerful, extensible, and framework-integrated database system inspired by Laravel's Eloquent & Query Builder — but designed natively for **Node.js & TypeScript**.
5
+
6
+ This package powers **DB facade**, **Models**, **Migrations**, and **Query Builder** across all ArikaJS applications.
7
+
8
+ ---
9
+
10
+ ## ✨ Features
11
+
12
+ ### ✅ Available (v0.x)
13
+ - ✅ Multiple database connections
14
+ - ✅ MySQL, PostgreSQL & SQLite support
15
+ - ✅ Fluent Query Builder
16
+ - ✅ Static Model querying
17
+ - ✅ Instance-style Models (Active Record)
18
+ - ✅ Relationships (hasOne, hasMany, belongsTo, belongsToMany)
19
+ - ✅ Eager Loading
20
+ - ✅ Query Scopes
21
+ - ✅ Soft Deletes
22
+ - ✅ DB Facade (`DB.table()`)
23
+ - ✅ Migrations & Schema Builder
24
+ - ✅ Database Seeders
25
+ - ✅ Framework-integrated configuration
26
+ - ✅ TypeScript-first design
27
+ - ✅ Works with native ArikaJS DI container
28
+
29
+ ---
30
+
31
+ ## 📦 Supported Drivers
32
+
33
+ | Driver | Status |
34
+ | --- | --- |
35
+ | MySQL | ✅ Supported |
36
+ | PostgreSQL | ✅ Supported |
37
+ | SQLite | ✅ Supported |
38
+
39
+ ---
40
+
41
+ ## 📦 Installation
42
+
43
+ ```bash
44
+ npm install @arikajs/database
45
+ ```
46
+
47
+ ---
48
+
49
+ ## ⚙️ Configuration
50
+
51
+ **config/database.ts**
52
+
53
+ ```typescript
54
+ import { env } from '@arikajs/config';
55
+
56
+ export default {
57
+ default: env('DB_CONNECTION', 'mysql'),
58
+
59
+ connections: {
60
+ mysql: {
61
+ driver: 'mysql',
62
+ host: env('DB_HOST', '127.0.0.1'),
63
+ port: env('DB_PORT', 3306),
64
+ database: env('DB_DATABASE', 'arikajs'),
65
+ username: env('DB_USERNAME', 'root'),
66
+ password: env('DB_PASSWORD', ''),
67
+ },
68
+
69
+ pgsql: {
70
+ driver: 'pgsql',
71
+ host: env('DB_HOST', '127.0.0.1'),
72
+ port: env('DB_PORT', 5432),
73
+ database: env('DB_DATABASE', 'arikajs'),
74
+ username: env('DB_USERNAME', 'postgres'),
75
+ password: env('DB_PASSWORD', ''),
76
+ },
77
+
78
+ sqlite: {
79
+ driver: 'sqlite',
80
+ database: env('DB_DATABASE', 'database.sqlite'),
81
+ },
82
+ },
83
+ };
84
+ ```
85
+
86
+ ---
87
+
88
+ ## 🧠 Usage
89
+
90
+ ### DB Facade (Query Builder)
91
+
92
+ ```typescript
93
+ import { DB } from '@arikajs/database';
94
+
95
+ const users = await DB.table('users')
96
+ .where('active', true)
97
+ .orderBy('id', 'desc')
98
+ .get();
99
+
100
+ await DB.table('users').insert({
101
+ name: 'John',
102
+ email: 'john@example.com',
103
+ });
104
+ ```
105
+
106
+ ### 🧬 Models (Static Style)
107
+
108
+ ```typescript
109
+ import { Model } from '@arikajs/database';
110
+
111
+ export class User extends Model {
112
+ static table = 'users';
113
+ }
114
+
115
+ const users = await User.where('active', true).get();
116
+ const user = await User.find(1);
117
+ ```
118
+
119
+ ### 💾 Instance-style Models
120
+
121
+ ```typescript
122
+ // Create new record
123
+ const user = new User();
124
+ user.name = 'John';
125
+ user.email = 'john@example.com';
126
+ await user.save();
127
+
128
+ // Update existing record
129
+ const user = await User.find(1);
130
+ user.name = 'Updated Name';
131
+ await user.save();
132
+
133
+ // Delete record
134
+ await user.deleteInstance();
135
+
136
+ // Dirty checking
137
+ user.name = 'New Name';
138
+ console.log(user.isDirty()); // true
139
+ console.log(user.getDirty()); // { name: 'New Name' }
140
+ ```
141
+
142
+ ### 🔗 Relationships
143
+
144
+ ```typescript
145
+ class User extends Model {
146
+ static table = 'users';
147
+
148
+ posts() {
149
+ return this.hasMany(Post, 'user_id');
150
+ }
151
+
152
+ profile() {
153
+ return this.hasOne(Profile, 'user_id');
154
+ }
155
+ }
156
+
157
+ class Post extends Model {
158
+ static table = 'posts';
159
+
160
+ author() {
161
+ return this.belongsTo(User, 'user_id');
162
+ }
163
+
164
+ tags() {
165
+ return this.belongsToMany(Tag, 'post_tag', 'post_id', 'tag_id');
166
+ }
167
+ }
168
+
169
+ // Using relationships
170
+ const user = await User.find(1);
171
+ const posts = await user.posts().get();
172
+ const profile = await user.profile().get();
173
+ ```
174
+
175
+ ### ⚡ Eager Loading
176
+
177
+ ```typescript
178
+ // Eager load relationships
179
+ const users = await User.with('posts').get();
180
+
181
+ // Eager load with constraints
182
+ const users = await User.with({
183
+ posts: q => q.where('published', true),
184
+ }).get();
185
+
186
+ // Multiple relationships
187
+ const users = await User.with(['posts', 'profile']).get();
188
+ ```
189
+
190
+ ### 🎯 Query Scopes
191
+
192
+ ```typescript
193
+ class User extends Model {
194
+ static table = 'users';
195
+
196
+ static active<T extends Model>(this: typeof Model) {
197
+ return this.query<T>().where('active', true);
198
+ }
199
+
200
+ static verified<T extends Model>(this: typeof Model) {
201
+ return this.query<T>().where('email_verified', true);
202
+ }
203
+ }
204
+
205
+ // Using scopes
206
+ const activeUsers = await User.active().get();
207
+ const verifiedActiveUsers = await User.active().verified().get();
208
+ ```
209
+
210
+ ### 🗑 Soft Deletes
211
+
212
+ ```typescript
213
+ import { Model, withSoftDeletes } from '@arikajs/database';
214
+
215
+ class User extends withSoftDeletes(Model) {
216
+ static table = 'users';
217
+ }
218
+
219
+ // Soft delete (sets deleted_at timestamp)
220
+ await User.delete(1);
221
+
222
+ // Get all records including soft deleted
223
+ const allUsers = await User.withTrashed().get();
224
+
225
+ // Get only soft deleted records
226
+ const trashedUsers = await User.onlyTrashed().get();
227
+
228
+ // Restore a soft deleted record
229
+ await User.restore(1);
230
+
231
+ // Permanently delete
232
+ await User.forceDelete(1);
233
+ ```
234
+
235
+ ### 🧱 Migrations (via CLI – planned)
236
+
237
+ ```bash
238
+ arika make:migration create_users_table
239
+ arika migrate
240
+ ```
241
+
242
+ ---
243
+
244
+ ## 🧩 Architecture Overview
245
+
246
+ ```
247
+ database/
248
+ ├── src/
249
+ │ ├── Connections/
250
+ │ │ ├── MySQLConnection
251
+ │ │ ├── PostgreSQLConnection
252
+ │ │ └── SQLiteConnection
253
+ │ ├── Model/
254
+ │ │ ├── Model
255
+ │ │ ├── Relations
256
+ │ │ └── SoftDeletes
257
+ │ ├── QueryBuilder
258
+ │ ├── Schema
259
+ │ ├── DatabaseManager
260
+ │ └── Facades/
261
+ │ └── DB
262
+ ├── config/
263
+ │ └── database.ts
264
+ └── README.md
265
+ ```
266
+
267
+ ---
268
+
269
+ ## 🚧 Planned Features (Roadmap)
270
+
271
+ The following features are designed and planned and will be introduced incrementally **without breaking existing APIs**.
272
+
273
+ ### 🎪 Model Events
274
+ ```typescript
275
+ class User extends Model {
276
+ static booted() {
277
+ this.creating((user) => {
278
+ user.uuid = generateUuid();
279
+ });
280
+
281
+ this.updated((user) => {
282
+ // Clear cache, send notifications, etc.
283
+ });
284
+ }
285
+ }
286
+ ```
287
+
288
+ ### ⚡ Query Result Caching
289
+ ```typescript
290
+ const users = await User.where('active', true)
291
+ .cache(3600) // Cache for 1 hour
292
+ .get();
293
+ ```
294
+
295
+ ### 🔍 Advanced Query Features
296
+ - Subqueries
297
+ - Union queries
298
+ - Raw expressions
299
+ - Database-specific functions
300
+
301
+ ---
302
+
303
+ ## 🧠 Design Philosophy
304
+
305
+ **"Power without magic."**
306
+
307
+ - One Query Builder
308
+ - No hidden globals
309
+ - Predictable SQL
310
+ - Laravel-like DX, Node.js performance
311
+
312
+ ---
313
+
314
+ ## 🔗 Framework Integration
315
+
316
+ - **@arikajs/foundation** → DI & lifecycle
317
+ - **@arikajs/config** → .env & config loading
318
+ - **@arikajs/cli** → migrations & generators
319
+ - **arikajs** → meta framework wiring
320
+
321
+ ---
322
+
323
+ ## 🧭 Versioning Strategy
324
+
325
+ - **0.x** → API stabilisation
326
+ - **1.0** → Stable contracts
327
+ - No breaking changes without major version bump
328
+
329
+ ---
330
+
331
+ ## 📄 License
332
+
333
+ MIT License © ArikaJS
@@ -0,0 +1,39 @@
1
+ import mysql from 'mysql2/promise';
2
+ import { Connection, ConnectionConfig } from '../Contracts/Database';
3
+ /**
4
+ * MySQL database connection
5
+ */
6
+ export declare class MySQLConnection implements Connection {
7
+ private pool;
8
+ private transactionConnection?;
9
+ constructor(config: ConnectionConfig);
10
+ /**
11
+ * Execute a raw SQL query
12
+ */
13
+ query(sql: string, bindings?: any[]): Promise<any>;
14
+ /**
15
+ * Begin a transaction
16
+ */
17
+ beginTransaction(): Promise<void>;
18
+ /**
19
+ * Commit a transaction
20
+ */
21
+ commit(): Promise<void>;
22
+ /**
23
+ * Rollback a transaction
24
+ */
25
+ rollback(): Promise<void>;
26
+ /**
27
+ * Close the connection
28
+ */
29
+ close(): Promise<void>;
30
+ /**
31
+ * Get the underlying driver connection
32
+ */
33
+ getDriver(): mysql.Pool;
34
+ /**
35
+ * Get the schema grammar for this connection
36
+ */
37
+ getSchemaGrammar(): any;
38
+ }
39
+ //# sourceMappingURL=MySQLConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MySQLConnection.d.ts","sourceRoot":"","sources":["../../src/Connections/MySQLConnection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,gBAAgB,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAErE;;GAEG;AACH,qBAAa,eAAgB,YAAW,UAAU;IAC9C,OAAO,CAAC,IAAI,CAAa;IACzB,OAAO,CAAC,qBAAqB,CAAC,CAAuB;gBAEzC,MAAM,EAAE,gBAAgB;IAepC;;OAEG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAM5D;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQvC;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAS7B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;OAEG;IACH,SAAS,IAAI,KAAK,CAAC,IAAI;IAIvB;;OAEG;IACH,gBAAgB;CAInB"}
@@ -0,0 +1,91 @@
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.MySQLConnection = void 0;
7
+ const promise_1 = __importDefault(require("mysql2/promise"));
8
+ /**
9
+ * MySQL database connection
10
+ */
11
+ class MySQLConnection {
12
+ constructor(config) {
13
+ this.pool = promise_1.default.createPool({
14
+ host: config.host,
15
+ port: config.port,
16
+ user: config.username,
17
+ password: config.password,
18
+ database: config.database,
19
+ charset: config.charset || 'utf8mb4',
20
+ timezone: config.timezone || '+00:00',
21
+ waitForConnections: true,
22
+ connectionLimit: config.pool?.max || 10,
23
+ queueLimit: 0,
24
+ });
25
+ }
26
+ /**
27
+ * Execute a raw SQL query
28
+ */
29
+ async query(sql, bindings = []) {
30
+ const connection = this.transactionConnection || this.pool;
31
+ const [rows] = await connection.execute(sql, bindings);
32
+ return rows;
33
+ }
34
+ /**
35
+ * Begin a transaction
36
+ */
37
+ async beginTransaction() {
38
+ if (this.transactionConnection) {
39
+ throw new Error('Transaction already started');
40
+ }
41
+ this.transactionConnection = await this.pool.getConnection();
42
+ await this.transactionConnection.beginTransaction();
43
+ }
44
+ /**
45
+ * Commit a transaction
46
+ */
47
+ async commit() {
48
+ if (!this.transactionConnection) {
49
+ throw new Error('No transaction to commit');
50
+ }
51
+ await this.transactionConnection.commit();
52
+ this.transactionConnection.release();
53
+ this.transactionConnection = undefined;
54
+ }
55
+ /**
56
+ * Rollback a transaction
57
+ */
58
+ async rollback() {
59
+ if (!this.transactionConnection) {
60
+ throw new Error('No transaction to rollback');
61
+ }
62
+ await this.transactionConnection.rollback();
63
+ this.transactionConnection.release();
64
+ this.transactionConnection = undefined;
65
+ }
66
+ /**
67
+ * Close the connection
68
+ */
69
+ async close() {
70
+ if (this.transactionConnection) {
71
+ this.transactionConnection.release();
72
+ this.transactionConnection = undefined;
73
+ }
74
+ await this.pool.end();
75
+ }
76
+ /**
77
+ * Get the underlying driver connection
78
+ */
79
+ getDriver() {
80
+ return this.pool;
81
+ }
82
+ /**
83
+ * Get the schema grammar for this connection
84
+ */
85
+ getSchemaGrammar() {
86
+ const { MySQLGrammar } = require('../Schema/Grammars/MySQLGrammar');
87
+ return new MySQLGrammar();
88
+ }
89
+ }
90
+ exports.MySQLConnection = MySQLConnection;
91
+ //# sourceMappingURL=MySQLConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MySQLConnection.js","sourceRoot":"","sources":["../../src/Connections/MySQLConnection.ts"],"names":[],"mappings":";;;;;;AAAA,6DAAmC;AAGnC;;GAEG;AACH,MAAa,eAAe;IAIxB,YAAY,MAAwB;QAChC,IAAI,CAAC,IAAI,GAAG,iBAAK,CAAC,UAAU,CAAC;YACzB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,SAAS;YACpC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,QAAQ;YACrC,kBAAkB,EAAE,IAAI;YACxB,eAAe,EAAE,MAAM,CAAC,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IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACP,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAC7B,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC;YACrC,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;QAC3C,CAAC;QACD,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;QACpE,OAAO,IAAI,YAAY,EAAE,CAAC;IAC9B,CAAC;CACJ;AAxFD,0CAwFC"}
@@ -0,0 +1,39 @@
1
+ import { Pool } from 'pg';
2
+ import { Connection, ConnectionConfig } from '../Contracts/Database';
3
+ /**
4
+ * PostgreSQL database connection
5
+ */
6
+ export declare class PostgreSQLConnection implements Connection {
7
+ private pool;
8
+ private transactionClient?;
9
+ constructor(config: ConnectionConfig);
10
+ /**
11
+ * Execute a raw SQL query
12
+ */
13
+ query(sql: string, bindings?: any[]): Promise<any>;
14
+ /**
15
+ * Begin a transaction
16
+ */
17
+ beginTransaction(): Promise<void>;
18
+ /**
19
+ * Commit a transaction
20
+ */
21
+ commit(): Promise<void>;
22
+ /**
23
+ * Rollback a transaction
24
+ */
25
+ rollback(): Promise<void>;
26
+ /**
27
+ * Close the connection
28
+ */
29
+ close(): Promise<void>;
30
+ /**
31
+ * Get the underlying driver connection
32
+ */
33
+ getDriver(): Pool;
34
+ /**
35
+ * Get the schema grammar for this connection
36
+ */
37
+ getSchemaGrammar(): any;
38
+ }
39
+ //# sourceMappingURL=PostgreSQLConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgreSQLConnection.d.ts","sourceRoot":"","sources":["../../src/Connections/PostgreSQLConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAc,MAAM,IAAI,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAErE;;GAEG;AACH,qBAAa,oBAAqB,YAAW,UAAU;IACnD,OAAO,CAAC,IAAI,CAAO;IACnB,OAAO,CAAC,iBAAiB,CAAC,CAAa;gBAE3B,MAAM,EAAE,gBAAgB;IAYpC;;OAEG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAM5D;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAQvC;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAS7B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;OAEG;IACH,SAAS,IAAI,IAAI;IAIjB;;OAEG;IACH,gBAAgB;CAInB"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PostgreSQLConnection = void 0;
4
+ const pg_1 = require("pg");
5
+ /**
6
+ * PostgreSQL database connection
7
+ */
8
+ class PostgreSQLConnection {
9
+ constructor(config) {
10
+ this.pool = new pg_1.Pool({
11
+ host: config.host,
12
+ port: config.port,
13
+ user: config.username,
14
+ password: config.password,
15
+ database: config.database,
16
+ min: config.pool?.min || 0,
17
+ max: config.pool?.max || 10,
18
+ });
19
+ }
20
+ /**
21
+ * Execute a raw SQL query
22
+ */
23
+ async query(sql, bindings = []) {
24
+ const client = this.transactionClient || this.pool;
25
+ const result = await client.query(sql, bindings);
26
+ return result.rows;
27
+ }
28
+ /**
29
+ * Begin a transaction
30
+ */
31
+ async beginTransaction() {
32
+ if (this.transactionClient) {
33
+ throw new Error('Transaction already started');
34
+ }
35
+ this.transactionClient = await this.pool.connect();
36
+ await this.transactionClient.query('BEGIN');
37
+ }
38
+ /**
39
+ * Commit a transaction
40
+ */
41
+ async commit() {
42
+ if (!this.transactionClient) {
43
+ throw new Error('No transaction to commit');
44
+ }
45
+ await this.transactionClient.query('COMMIT');
46
+ this.transactionClient.release();
47
+ this.transactionClient = undefined;
48
+ }
49
+ /**
50
+ * Rollback a transaction
51
+ */
52
+ async rollback() {
53
+ if (!this.transactionClient) {
54
+ throw new Error('No transaction to rollback');
55
+ }
56
+ await this.transactionClient.query('ROLLBACK');
57
+ this.transactionClient.release();
58
+ this.transactionClient = undefined;
59
+ }
60
+ /**
61
+ * Close the connection
62
+ */
63
+ async close() {
64
+ if (this.transactionClient) {
65
+ this.transactionClient.release();
66
+ this.transactionClient = undefined;
67
+ }
68
+ await this.pool.end();
69
+ }
70
+ /**
71
+ * Get the underlying driver connection
72
+ */
73
+ getDriver() {
74
+ return this.pool;
75
+ }
76
+ /**
77
+ * Get the schema grammar for this connection
78
+ */
79
+ getSchemaGrammar() {
80
+ const { PostgreSQLGrammar } = require('../Schema/Grammars/PostgreSQLGrammar');
81
+ return new PostgreSQLGrammar();
82
+ }
83
+ }
84
+ exports.PostgreSQLConnection = PostgreSQLConnection;
85
+ //# sourceMappingURL=PostgreSQLConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgreSQLConnection.js","sourceRoot":"","sources":["../../src/Connections/PostgreSQLConnection.ts"],"names":[],"mappings":";;;AAAA,2BAAsC;AAGtC;;GAEG;AACH,MAAa,oBAAoB;IAI7B,YAAY,MAAwB;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,SAAI,CAAC;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ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ACD,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC/C,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACP,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;YACjC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;QACvC,CAAC;QACD,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,gBAAgB;QACZ,MAAM,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,sCAAsC,CAAC,CAAC;QAC9E,OAAO,IAAI,iBAAiB,EAAE,CAAC;IACnC,CAAC;CACJ;AArFD,oDAqFC"}
@@ -0,0 +1,51 @@
1
+ import Database from 'better-sqlite3';
2
+ import { Connection, ConnectionConfig } from '../Contracts/Database';
3
+ /**
4
+ * SQLite database connection
5
+ */
6
+ export declare class SQLiteConnection implements Connection {
7
+ private db;
8
+ private config;
9
+ constructor(config: ConnectionConfig);
10
+ /**
11
+ * Connect to the database
12
+ */
13
+ connect(): Promise<void>;
14
+ /**
15
+ * Disconnect from the database
16
+ */
17
+ disconnect(): Promise<void>;
18
+ /**
19
+ * Execute a query
20
+ */
21
+ query(sql: string, bindings?: any[]): Promise<any[]>;
22
+ /**
23
+ * Execute a raw query
24
+ */
25
+ raw(sql: string): Promise<any>;
26
+ /**
27
+ * Get the underlying database instance
28
+ */
29
+ getDriver(): Database.Database;
30
+ /**
31
+ * Close the connection
32
+ */
33
+ close(): Promise<void>;
34
+ /**
35
+ * Begin a transaction
36
+ */
37
+ beginTransaction(): Promise<void>;
38
+ /**
39
+ * Commit a transaction
40
+ */
41
+ commit(): Promise<void>;
42
+ /**
43
+ * Rollback a transaction
44
+ */
45
+ rollback(): Promise<void>;
46
+ /**
47
+ * Get the schema grammar for this connection
48
+ */
49
+ getSchemaGrammar(): any;
50
+ }
51
+ //# sourceMappingURL=SQLiteConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SQLiteConnection.d.ts","sourceRoot":"","sources":["../../src/Connections/SQLiteConnection.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAErE;;GAEG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IAC/C,OAAO,CAAC,EAAE,CAAkC;IAC5C,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,EAAE,gBAAgB;IAIpC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;OAEG;IACG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAqB9D;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAYpC;;OAEG;IACH,SAAS,IAAI,QAAQ,CAAC,QAAQ;IAO9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvC;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B;;OAEG;IACH,gBAAgB;CAInB"}