@tyravel/database 0.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/dist/connection.d.ts +15 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +2 -0
- package/dist/connection.js.map +1 -0
- package/dist/database-manager.d.ts +12 -0
- package/dist/database-manager.d.ts.map +1 -0
- package/dist/database-manager.js +49 -0
- package/dist/database-manager.js.map +1 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.d.ts.map +1 -0
- package/dist/grammar.js +31 -0
- package/dist/grammar.js.map +1 -0
- package/dist/grammar.test.d.ts +2 -0
- package/dist/grammar.test.d.ts.map +1 -0
- package/dist/grammar.test.js +48 -0
- package/dist/grammar.test.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/migration.d.ts +13 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +3 -0
- package/dist/migration.js.map +1 -0
- package/dist/migrator.d.ts +15 -0
- package/dist/migrator.d.ts.map +1 -0
- package/dist/migrator.js +77 -0
- package/dist/migrator.js.map +1 -0
- package/dist/migrator.test.d.ts +2 -0
- package/dist/migrator.test.d.ts.map +1 -0
- package/dist/migrator.test.js +37 -0
- package/dist/migrator.test.js.map +1 -0
- package/dist/model-query-builder.d.ts +15 -0
- package/dist/model-query-builder.d.ts.map +1 -0
- package/dist/model-query-builder.js +43 -0
- package/dist/model-query-builder.js.map +1 -0
- package/dist/model-types.d.ts +14 -0
- package/dist/model-types.d.ts.map +1 -0
- package/dist/model-types.js +2 -0
- package/dist/model-types.js.map +1 -0
- package/dist/model.d.ts +41 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +135 -0
- package/dist/model.js.map +1 -0
- package/dist/model.test.d.ts +2 -0
- package/dist/model.test.d.ts.map +1 -0
- package/dist/model.test.js +32 -0
- package/dist/model.test.js.map +1 -0
- package/dist/mysql-connection.d.ts +13 -0
- package/dist/mysql-connection.d.ts.map +1 -0
- package/dist/mysql-connection.js +85 -0
- package/dist/mysql-connection.js.map +1 -0
- package/dist/postgres-connection.d.ts +13 -0
- package/dist/postgres-connection.d.ts.map +1 -0
- package/dist/postgres-connection.js +81 -0
- package/dist/postgres-connection.js.map +1 -0
- package/dist/query-builder.d.ts +45 -0
- package/dist/query-builder.d.ts.map +1 -0
- package/dist/query-builder.js +167 -0
- package/dist/query-builder.js.map +1 -0
- package/dist/query-builder.test.d.ts +2 -0
- package/dist/query-builder.test.d.ts.map +1 -0
- package/dist/query-builder.test.js +37 -0
- package/dist/query-builder.test.js.map +1 -0
- package/dist/relations/belongs-to-many.d.ts +13 -0
- package/dist/relations/belongs-to-many.d.ts.map +1 -0
- package/dist/relations/belongs-to-many.js +38 -0
- package/dist/relations/belongs-to-many.js.map +1 -0
- package/dist/relations/belongs-to.d.ts +10 -0
- package/dist/relations/belongs-to.d.ts.map +1 -0
- package/dist/relations/belongs-to.js +21 -0
- package/dist/relations/belongs-to.js.map +1 -0
- package/dist/relations/has-many.d.ts +12 -0
- package/dist/relations/has-many.d.ts.map +1 -0
- package/dist/relations/has-many.js +18 -0
- package/dist/relations/has-many.js.map +1 -0
- package/dist/relations/has-one.d.ts +12 -0
- package/dist/relations/has-one.d.ts.map +1 -0
- package/dist/relations/has-one.js +18 -0
- package/dist/relations/has-one.js.map +1 -0
- package/dist/relations/relation.d.ts +9 -0
- package/dist/relations/relation.d.ts.map +1 -0
- package/dist/relations/relation.js +9 -0
- package/dist/relations/relation.js.map +1 -0
- package/dist/relations.test.d.ts +2 -0
- package/dist/relations.test.d.ts.map +1 -0
- package/dist/relations.test.js +78 -0
- package/dist/relations.test.js.map +1 -0
- package/dist/schema/blueprint.d.ts +16 -0
- package/dist/schema/blueprint.d.ts.map +1 -0
- package/dist/schema/blueprint.js +59 -0
- package/dist/schema/blueprint.js.map +1 -0
- package/dist/schema/schema-builder.d.ts +10 -0
- package/dist/schema/schema-builder.d.ts.map +1 -0
- package/dist/schema/schema-builder.js +21 -0
- package/dist/schema/schema-builder.js.map +1 -0
- package/dist/scopes.d.ts +5 -0
- package/dist/scopes.d.ts.map +1 -0
- package/dist/scopes.js +4 -0
- package/dist/scopes.js.map +1 -0
- package/dist/scopes.test.d.ts +2 -0
- package/dist/scopes.test.d.ts.map +1 -0
- package/dist/scopes.test.js +48 -0
- package/dist/scopes.test.js.map +1 -0
- package/dist/sqlite-connection.d.ts +12 -0
- package/dist/sqlite-connection.d.ts.map +1 -0
- package/dist/sqlite-connection.js +60 -0
- package/dist/sqlite-connection.js.map +1 -0
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +15 -0
- package/dist/utils.js.map +1 -0
- package/package.json +40 -0
package/dist/model.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { applyGlobalScopes, ModelQueryBuilder } from './model-query-builder.js';
|
|
2
|
+
import { BelongsToManyRelation } from './relations/belongs-to-many.js';
|
|
3
|
+
import { BelongsToRelation } from './relations/belongs-to.js';
|
|
4
|
+
import { HasManyRelation } from './relations/has-many.js';
|
|
5
|
+
import { HasOneRelation } from './relations/has-one.js';
|
|
6
|
+
import { singularSnakeCase } from './utils.js';
|
|
7
|
+
export class Model {
|
|
8
|
+
static table = '';
|
|
9
|
+
static primaryKey = 'id';
|
|
10
|
+
static resolver;
|
|
11
|
+
static globalScopes = [];
|
|
12
|
+
attributes;
|
|
13
|
+
constructor(attributes = {}) {
|
|
14
|
+
this.attributes = { ...attributes };
|
|
15
|
+
}
|
|
16
|
+
static setConnectionResolver(resolver) {
|
|
17
|
+
this.resolver = resolver;
|
|
18
|
+
}
|
|
19
|
+
static useConnection(connection) {
|
|
20
|
+
this.setConnectionResolver(() => connection);
|
|
21
|
+
}
|
|
22
|
+
static addGlobalScope(scope) {
|
|
23
|
+
this.globalScopes.push(scope);
|
|
24
|
+
}
|
|
25
|
+
static getConnection() {
|
|
26
|
+
if (!this.resolver) {
|
|
27
|
+
throw new Error(`Database connection not configured for ${this.name}. Register DatabaseServiceProvider first.`);
|
|
28
|
+
}
|
|
29
|
+
return this.resolver();
|
|
30
|
+
}
|
|
31
|
+
static query() {
|
|
32
|
+
const model = this;
|
|
33
|
+
const builder = new ModelQueryBuilder(model.getConnection(), model.table, model);
|
|
34
|
+
return applyGlobalScopes(builder, this.globalScopes);
|
|
35
|
+
}
|
|
36
|
+
static scope(name, ...args) {
|
|
37
|
+
return this.query().applyScope(name, ...args);
|
|
38
|
+
}
|
|
39
|
+
static async find(id) {
|
|
40
|
+
const model = this;
|
|
41
|
+
return model.query().where(model.primaryKey, id).firstModel();
|
|
42
|
+
}
|
|
43
|
+
static async all() {
|
|
44
|
+
const model = this;
|
|
45
|
+
return model.query().getModels();
|
|
46
|
+
}
|
|
47
|
+
static async create(attributes) {
|
|
48
|
+
const model = this;
|
|
49
|
+
const id = await model.query().insert(attributes);
|
|
50
|
+
if (id !== undefined) {
|
|
51
|
+
const created = await this.find(id);
|
|
52
|
+
if (created) {
|
|
53
|
+
return created;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return new this(attributes);
|
|
57
|
+
}
|
|
58
|
+
static where(column, operatorOrValue, value) {
|
|
59
|
+
const model = this;
|
|
60
|
+
const builder = model.query();
|
|
61
|
+
if (operatorOrValue === undefined) {
|
|
62
|
+
return builder;
|
|
63
|
+
}
|
|
64
|
+
return builder.where(column, operatorOrValue, value);
|
|
65
|
+
}
|
|
66
|
+
hasMany(RelatedModel, foreignKey, localKey) {
|
|
67
|
+
const parentModel = this.constructor;
|
|
68
|
+
return new HasManyRelation(this, RelatedModel, foreignKey ?? `${singularSnakeCase(parentModel.name)}_id`, localKey ?? parentModel.primaryKey);
|
|
69
|
+
}
|
|
70
|
+
hasOne(RelatedModel, foreignKey, localKey) {
|
|
71
|
+
const parentModel = this.constructor;
|
|
72
|
+
return new HasOneRelation(this, RelatedModel, foreignKey ?? `${singularSnakeCase(parentModel.name)}_id`, localKey ?? parentModel.primaryKey);
|
|
73
|
+
}
|
|
74
|
+
belongsTo(RelatedModel, foreignKey, ownerKey) {
|
|
75
|
+
return new BelongsToRelation(this, RelatedModel, foreignKey ?? `${singularSnakeCase(RelatedModel.name)}_id`, ownerKey ?? RelatedModel.primaryKey);
|
|
76
|
+
}
|
|
77
|
+
belongsToMany(RelatedModel, pivotTable, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
|
|
78
|
+
const parentModel = this.constructor;
|
|
79
|
+
const parentSnake = singularSnakeCase(parentModel.name);
|
|
80
|
+
const relatedSnake = singularSnakeCase(RelatedModel.name);
|
|
81
|
+
return new BelongsToManyRelation(this, RelatedModel, pivotTable ?? `${parentSnake}_${relatedSnake}`, foreignPivotKey ?? `${parentSnake}_id`, relatedPivotKey ?? `${relatedSnake}_id`, parentKey ?? parentModel.primaryKey, relatedKey ?? RelatedModel.primaryKey);
|
|
82
|
+
}
|
|
83
|
+
getAttribute(key) {
|
|
84
|
+
return this.attributes[key];
|
|
85
|
+
}
|
|
86
|
+
setAttribute(key, value) {
|
|
87
|
+
this.attributes[key] = value;
|
|
88
|
+
}
|
|
89
|
+
toJSON() {
|
|
90
|
+
return { ...this.attributes };
|
|
91
|
+
}
|
|
92
|
+
async save() {
|
|
93
|
+
const model = this.constructor;
|
|
94
|
+
const primaryKey = model.primaryKey;
|
|
95
|
+
const id = this.attributes[primaryKey];
|
|
96
|
+
if (id === undefined || id === null) {
|
|
97
|
+
const insertedId = await model.query().insert(this.attributes);
|
|
98
|
+
if (insertedId !== undefined) {
|
|
99
|
+
this.setAttribute(primaryKey, insertedId);
|
|
100
|
+
}
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
await model
|
|
104
|
+
.query()
|
|
105
|
+
.where(primaryKey, id)
|
|
106
|
+
.update(this.attributes);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
async update(attributes) {
|
|
110
|
+
Object.assign(this.attributes, attributes);
|
|
111
|
+
return this.save();
|
|
112
|
+
}
|
|
113
|
+
async delete() {
|
|
114
|
+
const model = this.constructor;
|
|
115
|
+
const primaryKey = model.primaryKey;
|
|
116
|
+
const id = this.attributes[primaryKey];
|
|
117
|
+
if (id === undefined || id === null) {
|
|
118
|
+
throw new Error(`Cannot delete ${model.name} without a primary key.`);
|
|
119
|
+
}
|
|
120
|
+
await model.query().where(primaryKey, id).delete();
|
|
121
|
+
}
|
|
122
|
+
async fresh() {
|
|
123
|
+
const model = this.constructor;
|
|
124
|
+
const primaryKey = model.primaryKey;
|
|
125
|
+
const id = this.attributes[primaryKey];
|
|
126
|
+
if (id === undefined || id === null) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return model.find(normalizeId(id));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function normalizeId(id) {
|
|
133
|
+
return typeof id === 'bigint' ? Number(id) : id;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAEhF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAIxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAI/C,MAAM,OAAO,KAAK;IAChB,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,MAAM,CAAC,UAAU,GAAG,IAAI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K,SAAS,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,CAAC,IAAI,yBAAyB,CAAC,CAAC;QACxE,CAAC;QAED,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,EAAc,CAAC,CAAC,MAAM,EAAE,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,GAAG,IAAI,CAAC,WAAqC,CAAC;QACzD,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACpC,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,UAAqB,CAAC,CAAC;QAElD,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAc,CAAC,CAA2B,CAAC;IAC3E,CAAC;;AAGH,SAAS,WAAW,CAAC,EAAqB;IACxC,OAAO,OAAO,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.test.d.ts","sourceRoot":"","sources":["../src/model.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { Model } from './model.js';
|
|
3
|
+
import { SqliteConnection } from './sqlite-connection.js';
|
|
4
|
+
class User extends Model {
|
|
5
|
+
static table = 'users';
|
|
6
|
+
}
|
|
7
|
+
describe('Model', () => {
|
|
8
|
+
it('supports eloquent-style create, find, update, and delete', async () => {
|
|
9
|
+
const connection = new SqliteConnection(':memory:');
|
|
10
|
+
User.useConnection(connection);
|
|
11
|
+
await connection.exec(`
|
|
12
|
+
CREATE TABLE "users" (
|
|
13
|
+
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
14
|
+
"name" TEXT NOT NULL,
|
|
15
|
+
"email" TEXT NOT NULL
|
|
16
|
+
)
|
|
17
|
+
`);
|
|
18
|
+
const user = await User.create({
|
|
19
|
+
name: 'Ada Lovelace',
|
|
20
|
+
email: 'ada@example.com',
|
|
21
|
+
});
|
|
22
|
+
expect(user.getAttribute('name')).toBe('Ada Lovelace');
|
|
23
|
+
const found = await User.find(user.getAttribute('id'));
|
|
24
|
+
expect(found?.getAttribute('email')).toBe('ada@example.com');
|
|
25
|
+
await user.update({ name: 'Grace Hopper' });
|
|
26
|
+
const fresh = await user.fresh();
|
|
27
|
+
expect(fresh?.getAttribute('name')).toBe('Grace Hopper');
|
|
28
|
+
await user.delete();
|
|
29
|
+
expect(await User.find(user.getAttribute('id'))).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=model.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.test.js","sourceRoot":"","sources":["../src/model.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAS1D,MAAM,IAAK,SAAQ,KAAc;IAC/B,MAAM,CAAU,KAAK,GAAG,OAAO,CAAC;;AAGlC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACxE,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACpD,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAE/B,MAAM,UAAU,CAAC,IAAI,CAAC;;;;;;KAMrB,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC;YAC7B,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,iBAAiB;SACzB,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEvD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAE,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAE7D,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QAC5C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACjC,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEzD,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DatabaseConnection, QueryResult } from './connection.js';
|
|
2
|
+
import { type SqlGrammar } from './grammar.js';
|
|
3
|
+
import type { MysqlConnectionConfig, RowValue } from './types.js';
|
|
4
|
+
export declare class MysqlConnection implements DatabaseConnection {
|
|
5
|
+
readonly grammar: SqlGrammar;
|
|
6
|
+
private readonly pool;
|
|
7
|
+
constructor(config: MysqlConnectionConfig);
|
|
8
|
+
query(sql: string, bindings?: RowValue[]): Promise<QueryResult>;
|
|
9
|
+
exec(sql: string): Promise<void>;
|
|
10
|
+
transaction<T>(callback: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=mysql-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql-connection.d.ts","sourceRoot":"","sources":["../src/mysql-connection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAElE,qBAAa,eAAgB,YAAW,kBAAkB;IACxD,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAsB;IAClD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAEtB,MAAM,EAAE,qBAAqB;IAUnC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,QAAQ,EAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAkBnE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhC,WAAW,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,GACvD,OAAO,CAAC,CAAC,CAAC;IAiBP,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import mysql from 'mysql2/promise';
|
|
2
|
+
import { MysqlGrammar } from './grammar.js';
|
|
3
|
+
export class MysqlConnection {
|
|
4
|
+
grammar = new MysqlGrammar();
|
|
5
|
+
pool;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.pool = mysql.createPool({
|
|
8
|
+
host: config.host,
|
|
9
|
+
port: config.port ?? 3306,
|
|
10
|
+
database: config.database,
|
|
11
|
+
user: config.username,
|
|
12
|
+
password: config.password,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async query(sql, bindings = []) {
|
|
16
|
+
const [result] = await this.pool.query(sql, normalizeBindings(bindings));
|
|
17
|
+
if (Array.isArray(result)) {
|
|
18
|
+
return {
|
|
19
|
+
rows: result,
|
|
20
|
+
changes: 0,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const header = result;
|
|
24
|
+
return {
|
|
25
|
+
rows: [],
|
|
26
|
+
changes: header.affectedRows,
|
|
27
|
+
lastInsertId: header.insertId,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async exec(sql) {
|
|
31
|
+
await this.pool.query(sql);
|
|
32
|
+
}
|
|
33
|
+
async transaction(callback) {
|
|
34
|
+
const connection = await this.pool.getConnection();
|
|
35
|
+
try {
|
|
36
|
+
await connection.beginTransaction();
|
|
37
|
+
const transactional = new MysqlTransactionConnection(connection);
|
|
38
|
+
const result = await callback(transactional);
|
|
39
|
+
await connection.commit();
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
await connection.rollback();
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
connection.release();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async close() {
|
|
51
|
+
await this.pool.end();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class MysqlTransactionConnection {
|
|
55
|
+
connection;
|
|
56
|
+
grammar = new MysqlGrammar();
|
|
57
|
+
constructor(connection) {
|
|
58
|
+
this.connection = connection;
|
|
59
|
+
}
|
|
60
|
+
async query(sql, bindings = []) {
|
|
61
|
+
const [result] = await this.connection.query(sql, normalizeBindings(bindings));
|
|
62
|
+
if (Array.isArray(result)) {
|
|
63
|
+
return {
|
|
64
|
+
rows: result,
|
|
65
|
+
changes: 0,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const header = result;
|
|
69
|
+
return {
|
|
70
|
+
rows: [],
|
|
71
|
+
changes: header.affectedRows,
|
|
72
|
+
lastInsertId: header.insertId,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async exec(sql) {
|
|
76
|
+
await this.connection.query(sql);
|
|
77
|
+
}
|
|
78
|
+
async transaction(callback) {
|
|
79
|
+
return callback(this);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function normalizeBindings(bindings) {
|
|
83
|
+
return bindings.map((binding) => (binding === undefined ? null : binding));
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=mysql-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql-connection.js","sourceRoot":"","sources":["../src/mysql-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAmB,MAAM,cAAc,CAAC;AAG7D,MAAM,OAAO,eAAe;IACjB,OAAO,GAAe,IAAI,YAAY,EAAE,CAAC;IACjC,IAAI,CAAa;IAElC,YAAY,MAA6B;QACvC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC;YAC3B,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,WAAuB,EAAE;QAChD,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEzE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO;gBACL,IAAI,EA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C,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE/E,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO;gBACL,IAAI,EAAE,MAAmC;gBACzC,OAAO,EAAE,CAAC;aACX,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,MAA+B,CAAC;QAC/C,OAAO;YACL,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,MAAM,CAAC,YAAY;YAC5B,YAAY,EAAE,MAAM,CAAC,QAAQ;SAC9B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAW;QACpB,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,WAAW,CACf,QAAwD;QAExD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,QAAoB;IAC7C,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DatabaseConnection, QueryResult } from './connection.js';
|
|
2
|
+
import { type SqlGrammar } from './grammar.js';
|
|
3
|
+
import type { PostgresConnectionConfig, RowValue } from './types.js';
|
|
4
|
+
export declare class PostgresConnection implements DatabaseConnection {
|
|
5
|
+
readonly grammar: SqlGrammar;
|
|
6
|
+
private readonly pool;
|
|
7
|
+
constructor(config: PostgresConnectionConfig);
|
|
8
|
+
query(sql: string, bindings?: RowValue[]): Promise<QueryResult>;
|
|
9
|
+
exec(sql: string): Promise<void>;
|
|
10
|
+
transaction<T>(callback: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=postgres-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-connection.d.ts","sourceRoot":"","sources":["../src/postgres-connection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAIrE,qBAAa,kBAAmB,YAAW,kBAAkB;IAC3D,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAyB;IACrD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;gBAEnB,MAAM,EAAE,wBAAwB;IAWtC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,QAAQ,EAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAenE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhC,WAAW,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,GACvD,OAAO,CAAC,CAAC,CAAC;IAiBP,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import pg from 'pg';
|
|
2
|
+
import { PostgresGrammar } from './grammar.js';
|
|
3
|
+
const { Pool } = pg;
|
|
4
|
+
export class PostgresConnection {
|
|
5
|
+
grammar = new PostgresGrammar();
|
|
6
|
+
pool;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.pool = new Pool({
|
|
9
|
+
host: config.host,
|
|
10
|
+
port: config.port ?? 5432,
|
|
11
|
+
database: config.database,
|
|
12
|
+
user: config.username,
|
|
13
|
+
password: config.password,
|
|
14
|
+
ssl: config.ssl ? { rejectUnauthorized: false } : undefined,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
async query(sql, bindings = []) {
|
|
18
|
+
const result = await this.pool.query(sql, normalizeBindings(bindings));
|
|
19
|
+
const rows = result.rows;
|
|
20
|
+
const lastInsertId = rows[0]?.id;
|
|
21
|
+
return {
|
|
22
|
+
rows,
|
|
23
|
+
changes: result.rowCount ?? 0,
|
|
24
|
+
lastInsertId: typeof lastInsertId === 'number' || typeof lastInsertId === 'bigint'
|
|
25
|
+
? lastInsertId
|
|
26
|
+
: undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async exec(sql) {
|
|
30
|
+
await this.pool.query(sql);
|
|
31
|
+
}
|
|
32
|
+
async transaction(callback) {
|
|
33
|
+
const client = await this.pool.connect();
|
|
34
|
+
try {
|
|
35
|
+
await client.query('BEGIN');
|
|
36
|
+
const connection = new PostgresTransactionConnection(client);
|
|
37
|
+
const result = await callback(connection);
|
|
38
|
+
await client.query('COMMIT');
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
await client.query('ROLLBACK');
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
client.release();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async close() {
|
|
50
|
+
await this.pool.end();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class PostgresTransactionConnection {
|
|
54
|
+
client;
|
|
55
|
+
grammar = new PostgresGrammar();
|
|
56
|
+
constructor(client) {
|
|
57
|
+
this.client = client;
|
|
58
|
+
}
|
|
59
|
+
async query(sql, bindings = []) {
|
|
60
|
+
const result = await this.client.query(sql, normalizeBindings(bindings));
|
|
61
|
+
const rows = result.rows;
|
|
62
|
+
const lastInsertId = rows[0]?.id;
|
|
63
|
+
return {
|
|
64
|
+
rows,
|
|
65
|
+
changes: result.rowCount ?? 0,
|
|
66
|
+
lastInsertId: typeof lastInsertId === 'number' || typeof lastInsertId === 'bigint'
|
|
67
|
+
? lastInsertId
|
|
68
|
+
: undefined,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async exec(sql) {
|
|
72
|
+
await this.client.query(sql);
|
|
73
|
+
}
|
|
74
|
+
async transaction(callback) {
|
|
75
|
+
return callback(this);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function normalizeBindings(bindings) {
|
|
79
|
+
return bindings.map((binding) => (binding === undefined ? null : binding));
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=postgres-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-connection.js","sourceRoot":"","sources":["../src/postgres-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,EAAE,eAAe,EAAmB,MAAM,cAAc,CAAC;AAGhE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAEpB,MAAM,OAAO,kBAAkB;IACpB,OAAO,GAAe,IAAI,eAAe,EAAE,CAAC;IACpC,IAAI,CAAU;IAE/B,YAAY,MAAgC;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS;SAC5D,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,WAAuB,EAAE;QAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,G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AI,eAAe,EAAE,CAAC;IAErD,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,WAAuB,EAAE;QAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAiC,CAAC;QACtD,MAAM,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAEjC,OAAO;YACL,IAAI;YACJ,OAAO,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC;YAC7B,YAAY,EACV,OAAO,YAAY,KAAK,QAAQ,IAAI,OAAO,YAAY,KAAK,QAAQ;gBAClE,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,SAAS;SAChB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAW;QACpB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,WAAW,CACf,QAAwD;QAExD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,QAAoB;IAC7C,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { DatabaseConnection } from './connection.js';
|
|
2
|
+
import type { SqlGrammar } from './grammar.js';
|
|
3
|
+
import type { Row, RowValue, WhereClause, WhereOperator } from './types.js';
|
|
4
|
+
export declare class QueryBuilder<T extends Row = Row> {
|
|
5
|
+
protected readonly connection: DatabaseConnection;
|
|
6
|
+
protected readonly tableName: string;
|
|
7
|
+
protected columns: string[];
|
|
8
|
+
protected wheres: WhereClause[];
|
|
9
|
+
protected orders: Array<{
|
|
10
|
+
column: string;
|
|
11
|
+
direction: 'asc' | 'desc';
|
|
12
|
+
}>;
|
|
13
|
+
protected limitCount?: number;
|
|
14
|
+
protected offsetCount?: number;
|
|
15
|
+
protected readonly grammar: SqlGrammar;
|
|
16
|
+
constructor(connection: DatabaseConnection, tableName: string);
|
|
17
|
+
getQueryConnection(): DatabaseConnection;
|
|
18
|
+
getTableName(): string;
|
|
19
|
+
select(...columns: string[]): this;
|
|
20
|
+
where(column: string, operatorOrValue: WhereOperator | RowValue, value?: RowValue): this;
|
|
21
|
+
whereIn(column: string, values: RowValue[]): this;
|
|
22
|
+
orderBy(column: string, direction?: 'asc' | 'desc'): this;
|
|
23
|
+
limit(count: number): this;
|
|
24
|
+
offset(count: number): this;
|
|
25
|
+
clone(): QueryBuilder<T>;
|
|
26
|
+
protected copyTo(builder: QueryBuilder<T>): void;
|
|
27
|
+
get(): Promise<T[]>;
|
|
28
|
+
first(): Promise<T | null>;
|
|
29
|
+
insert(attributes: Partial<T>): Promise<number | bigint | undefined>;
|
|
30
|
+
update(attributes: Partial<T>): Promise<number>;
|
|
31
|
+
delete(): Promise<number>;
|
|
32
|
+
toSql(): {
|
|
33
|
+
sql: string;
|
|
34
|
+
bindings: RowValue[];
|
|
35
|
+
};
|
|
36
|
+
protected buildSelect(): {
|
|
37
|
+
sql: string;
|
|
38
|
+
bindings: RowValue[];
|
|
39
|
+
};
|
|
40
|
+
protected compileWheres(bindings: RowValue[], bindingOffset?: number): {
|
|
41
|
+
sql: string;
|
|
42
|
+
};
|
|
43
|
+
private placeholderList;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=query-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-builder.d.ts","sourceRoot":"","sources":["../src/query-builder.ts"],"names":[],"mappings":"A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,MAAM,GAAG,IAAI;IAK1B,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK3B,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC;IAMxB,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI;IAQ1C,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC;IAMnB,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAK1B,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAmBpE,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAc/C,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAQ/B,KAAK,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,QAAQ,EAAE,CAAA;KAAE;IAI9C,SAAS,CAAC,WAAW,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,QAAQ,EAAE,CAAA;KAAE;IAgC9D,SAAS,CAAC,aAAa,CACrB,QAAQ,EAAE,QAAQ,EAAE,EACpB,aAAa,SAAI,GAChB;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;IA+BlB,OAAO,CAAC,eAAe;CAKxB"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export class QueryBuilder {
|
|
2
|
+
connection;
|
|
3
|
+
tableName;
|
|
4
|
+
columns = ['*'];
|
|
5
|
+
wheres = [];
|
|
6
|
+
orders = [];
|
|
7
|
+
limitCount;
|
|
8
|
+
offsetCount;
|
|
9
|
+
grammar;
|
|
10
|
+
constructor(connection, tableName) {
|
|
11
|
+
this.connection = connection;
|
|
12
|
+
this.tableName = tableName;
|
|
13
|
+
this.grammar = connection.grammar;
|
|
14
|
+
}
|
|
15
|
+
getQueryConnection() {
|
|
16
|
+
return this.connection;
|
|
17
|
+
}
|
|
18
|
+
getTableName() {
|
|
19
|
+
return this.tableName;
|
|
20
|
+
}
|
|
21
|
+
select(...columns) {
|
|
22
|
+
this.columns = columns.length > 0 ? columns : ['*'];
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
where(column, operatorOrValue, value) {
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
this.wheres.push({
|
|
28
|
+
type: 'basic',
|
|
29
|
+
column,
|
|
30
|
+
operator: '=',
|
|
31
|
+
value: operatorOrValue,
|
|
32
|
+
boolean: 'and',
|
|
33
|
+
});
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
this.wheres.push({
|
|
37
|
+
type: 'basic',
|
|
38
|
+
column,
|
|
39
|
+
operator: operatorOrValue,
|
|
40
|
+
value,
|
|
41
|
+
boolean: 'and',
|
|
42
|
+
});
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
whereIn(column, values) {
|
|
46
|
+
this.wheres.push({
|
|
47
|
+
type: 'in',
|
|
48
|
+
column,
|
|
49
|
+
operator: 'in',
|
|
50
|
+
value: values,
|
|
51
|
+
boolean: 'and',
|
|
52
|
+
});
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
orderBy(column, direction = 'asc') {
|
|
56
|
+
this.orders.push({ column, direction });
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
limit(count) {
|
|
60
|
+
this.limitCount = count;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
offset(count) {
|
|
64
|
+
this.offsetCount = count;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
clone() {
|
|
68
|
+
const builder = new QueryBuilder(this.connection, this.tableName);
|
|
69
|
+
this.copyTo(builder);
|
|
70
|
+
return builder;
|
|
71
|
+
}
|
|
72
|
+
copyTo(builder) {
|
|
73
|
+
builder.columns = [...this.columns];
|
|
74
|
+
builder.wheres = [...this.wheres];
|
|
75
|
+
builder.orders = [...this.orders];
|
|
76
|
+
builder.limitCount = this.limitCount;
|
|
77
|
+
builder.offsetCount = this.offsetCount;
|
|
78
|
+
}
|
|
79
|
+
async get() {
|
|
80
|
+
const { sql, bindings } = this.buildSelect();
|
|
81
|
+
const result = await this.connection.query(sql, bindings);
|
|
82
|
+
return result.rows;
|
|
83
|
+
}
|
|
84
|
+
async first() {
|
|
85
|
+
const rows = await this.clone().limit(1).get();
|
|
86
|
+
return rows[0] ?? null;
|
|
87
|
+
}
|
|
88
|
+
async insert(attributes) {
|
|
89
|
+
const entries = Object.entries(attributes).filter(([, value]) => value !== undefined);
|
|
90
|
+
const columns = entries.map(([column]) => this.grammar.wrapIdentifier(column));
|
|
91
|
+
const bindings = entries.map(([, value]) => value);
|
|
92
|
+
const placeholders = this.placeholderList(bindings.length);
|
|
93
|
+
let sql = `INSERT INTO ${this.grammar.wrapIdentifier(this.tableName)} (${columns.join(', ')}) VALUES (${placeholders.join(', ')})`;
|
|
94
|
+
if (this.grammar.supportsReturning) {
|
|
95
|
+
sql += ` RETURNING ${this.grammar.wrapIdentifier('id')}`;
|
|
96
|
+
const result = await this.connection.query(sql, bindings);
|
|
97
|
+
const id = result.rows[0]?.id;
|
|
98
|
+
return typeof id === 'number' || typeof id === 'bigint' ? id : undefined;
|
|
99
|
+
}
|
|
100
|
+
const result = await this.connection.query(sql, bindings);
|
|
101
|
+
return result.lastInsertId;
|
|
102
|
+
}
|
|
103
|
+
async update(attributes) {
|
|
104
|
+
const entries = Object.entries(attributes).filter(([, value]) => value !== undefined);
|
|
105
|
+
const bindings = entries.map(([, value]) => value);
|
|
106
|
+
const sets = entries.map(([column], index) => `${this.grammar.wrapIdentifier(column)} = ${this.grammar.parameter(index + 1)}`);
|
|
107
|
+
const whereBindings = [];
|
|
108
|
+
const where = this.compileWheres(whereBindings, bindings.length);
|
|
109
|
+
const sql = `UPDATE ${this.grammar.wrapIdentifier(this.tableName)} SET ${sets.join(', ')}${where.sql}`;
|
|
110
|
+
const result = await this.connection.query(sql, [...bindings, ...whereBindings]);
|
|
111
|
+
return result.changes;
|
|
112
|
+
}
|
|
113
|
+
async delete() {
|
|
114
|
+
const bindings = [];
|
|
115
|
+
const where = this.compileWheres(bindings);
|
|
116
|
+
const sql = `DELETE FROM ${this.grammar.wrapIdentifier(this.tableName)}${where.sql}`;
|
|
117
|
+
const result = await this.connection.query(sql, bindings);
|
|
118
|
+
return result.changes;
|
|
119
|
+
}
|
|
120
|
+
toSql() {
|
|
121
|
+
return this.buildSelect();
|
|
122
|
+
}
|
|
123
|
+
buildSelect() {
|
|
124
|
+
const bindings = [];
|
|
125
|
+
const columns = this.columns.map((column) => column === '*' ? '*' : this.grammar.wrapIdentifier(column));
|
|
126
|
+
const where = this.compileWheres(bindings);
|
|
127
|
+
let sql = `SELECT ${columns.join(', ')} FROM ${this.grammar.wrapIdentifier(this.tableName)}${where.sql}`;
|
|
128
|
+
if (this.orders.length > 0) {
|
|
129
|
+
const orderings = this.orders
|
|
130
|
+
.map((order) => `${this.grammar.wrapIdentifier(order.column)} ${order.direction.toUpperCase()}`)
|
|
131
|
+
.join(', ');
|
|
132
|
+
sql += ` ORDER BY ${orderings}`;
|
|
133
|
+
}
|
|
134
|
+
if (this.limitCount !== undefined) {
|
|
135
|
+
sql += ` LIMIT ${this.grammar.parameter(bindings.length + 1)}`;
|
|
136
|
+
bindings.push(this.limitCount);
|
|
137
|
+
}
|
|
138
|
+
if (this.offsetCount !== undefined) {
|
|
139
|
+
sql += ` OFFSET ${this.grammar.parameter(bindings.length + 1)}`;
|
|
140
|
+
bindings.push(this.offsetCount);
|
|
141
|
+
}
|
|
142
|
+
return { sql, bindings };
|
|
143
|
+
}
|
|
144
|
+
compileWheres(bindings, bindingOffset = 0) {
|
|
145
|
+
if (this.wheres.length === 0) {
|
|
146
|
+
return { sql: '' };
|
|
147
|
+
}
|
|
148
|
+
const parts = [];
|
|
149
|
+
for (const [index, clause] of this.wheres.entries()) {
|
|
150
|
+
const prefix = index === 0 ? ' WHERE ' : ` ${clause.boolean.toUpperCase()} `;
|
|
151
|
+
if (clause.type === 'in') {
|
|
152
|
+
const values = clause.value;
|
|
153
|
+
const placeholders = values.map((_, valueIndex) => this.grammar.parameter(bindingOffset + bindings.length + valueIndex + 1));
|
|
154
|
+
parts.push(`${prefix}${this.grammar.wrapIdentifier(clause.column)} IN (${placeholders.join(', ')})`);
|
|
155
|
+
bindings.push(...values);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
parts.push(`${prefix}${this.grammar.wrapIdentifier(clause.column)} ${clause.operator} ${this.grammar.parameter(bindingOffset + bindings.length + 1)}`);
|
|
159
|
+
bindings.push(clause.value);
|
|
160
|
+
}
|
|
161
|
+
return { sql: parts.join('') };
|
|
162
|
+
}
|
|
163
|
+
placeholderList(count) {
|
|
164
|
+
return Array.from({ length: count }, (_, index) => this.grammar.parameter(index + 1));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=query-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-builder.js","sourceRoot":"","sources":["../src/query-builder.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,YAAY;IASF;IACA;IATX,OAAO,GAAa,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,GAAkB,EAAE,CAAC;IAC3B,MAAM,GAAyD,EAAE,CAAC;IAClE,UAAU,CAAU;IACpB,WAAW,CAAU;IACZ,OAAO,CAAa;IAEvC,YACqB,UAA8B,EAC9B,SAAiB;QADjB,eAAU,GAAV,UAAU,CAAoB;QAC9B,cAAS,GAAT,SAAS,CAAQ;QAEpC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IACpC,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,MAAM,CAAC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