@itrocks/mysql 0.1.6 → 0.1.7
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/cjs/mysql.d.ts +1 -0
- package/cjs/mysql.js +8 -5
- package/esm/mysql.d.ts +1 -0
- package/esm/mysql.js +8 -5
- package/package.json +1 -1
package/cjs/mysql.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ export declare class Mysql extends DataSource {
|
|
|
64
64
|
saveComponents<T extends object>(object: Entity<T>, property: KeyOf<T>, components: (Identifier | MayEntity)[]): Promise<void>;
|
|
65
65
|
saveLinks<T extends object>(object: Entity<T>, property: KeyOf<T>, links: (Identifier | MayEntity)[]): Promise<void>;
|
|
66
66
|
search<T extends object>(type: Type<T>, search?: SearchType<T>, options?: Options): Promise<Entity<T>[]>;
|
|
67
|
+
targetName<T extends object>(property: ReflectProperty<T>): string;
|
|
67
68
|
update<T extends object>(object: Entity<T>): Promise<Entity<T>>;
|
|
68
69
|
valuesFromDb<T extends object>(record: Entity<T>, type: Type<T>): Promise<Entity<T>>;
|
|
69
70
|
valuesToDb<T extends object>(object: T): Promise<[AnyObject, Function[]]>;
|
package/cjs/mysql.js
CHANGED
|
@@ -51,10 +51,7 @@ class Mysql extends storage_1.DataSource {
|
|
|
51
51
|
const propertyType = property.type;
|
|
52
52
|
if (propertyType instanceof property_type_1.CollectionType)
|
|
53
53
|
return;
|
|
54
|
-
|
|
55
|
-
? property.name + 'Id'
|
|
56
|
-
: property.name;
|
|
57
|
-
return depends.columnOf(propertyName);
|
|
54
|
+
return depends.columnOf(this.targetName(property));
|
|
58
55
|
}
|
|
59
56
|
async connect() {
|
|
60
57
|
const mariaDbConfig = Object.assign(this.config, {
|
|
@@ -157,7 +154,7 @@ class Mysql extends storage_1.DataSource {
|
|
|
157
154
|
const columnName = this.columnName(property);
|
|
158
155
|
if (!columnName)
|
|
159
156
|
continue;
|
|
160
|
-
const propertyName = property
|
|
157
|
+
const propertyName = this.targetName(property);
|
|
161
158
|
sql.push((columnName.length !== propertyName.length)
|
|
162
159
|
? ('`' + columnName + '` `' + propertyName + '`')
|
|
163
160
|
: ('`' + propertyName + '`'));
|
|
@@ -363,6 +360,12 @@ class Mysql extends storage_1.DataSource {
|
|
|
363
360
|
const rows = await connection.query('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '`' + sql + sort + limit + offset, Object.values(values));
|
|
364
361
|
return Promise.all(rows.map(row => this.valuesFromDb(row, type)));
|
|
365
362
|
}
|
|
363
|
+
targetName(property) {
|
|
364
|
+
const type = property.type.type;
|
|
365
|
+
return ((0, class_type_3.isAnyType)(type) && depends.storeOf(type))
|
|
366
|
+
? property.name + 'Id'
|
|
367
|
+
: property.name;
|
|
368
|
+
}
|
|
366
369
|
async update(object) {
|
|
367
370
|
const connection = this.connection ?? await this.connect();
|
|
368
371
|
const [values, deferred] = await this.valuesToDb(object);
|
package/esm/mysql.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ export declare class Mysql extends DataSource {
|
|
|
64
64
|
saveComponents<T extends object>(object: Entity<T>, property: KeyOf<T>, components: (Identifier | MayEntity)[]): Promise<void>;
|
|
65
65
|
saveLinks<T extends object>(object: Entity<T>, property: KeyOf<T>, links: (Identifier | MayEntity)[]): Promise<void>;
|
|
66
66
|
search<T extends object>(type: Type<T>, search?: SearchType<T>, options?: Options): Promise<Entity<T>[]>;
|
|
67
|
+
targetName<T extends object>(property: ReflectProperty<T>): string;
|
|
67
68
|
update<T extends object>(object: Entity<T>): Promise<Entity<T>>;
|
|
68
69
|
valuesFromDb<T extends object>(record: Entity<T>, type: Type<T>): Promise<Entity<T>>;
|
|
69
70
|
valuesToDb<T extends object>(object: T): Promise<[AnyObject, Function[]]>;
|
package/esm/mysql.js
CHANGED
|
@@ -46,10 +46,7 @@ export class Mysql extends DataSource {
|
|
|
46
46
|
const propertyType = property.type;
|
|
47
47
|
if (propertyType instanceof CollectionType)
|
|
48
48
|
return;
|
|
49
|
-
|
|
50
|
-
? property.name + 'Id'
|
|
51
|
-
: property.name;
|
|
52
|
-
return depends.columnOf(propertyName);
|
|
49
|
+
return depends.columnOf(this.targetName(property));
|
|
53
50
|
}
|
|
54
51
|
async connect() {
|
|
55
52
|
const mariaDbConfig = Object.assign(this.config, {
|
|
@@ -152,7 +149,7 @@ export class Mysql extends DataSource {
|
|
|
152
149
|
const columnName = this.columnName(property);
|
|
153
150
|
if (!columnName)
|
|
154
151
|
continue;
|
|
155
|
-
const propertyName = property
|
|
152
|
+
const propertyName = this.targetName(property);
|
|
156
153
|
sql.push((columnName.length !== propertyName.length)
|
|
157
154
|
? ('`' + columnName + '` `' + propertyName + '`')
|
|
158
155
|
: ('`' + propertyName + '`'));
|
|
@@ -358,6 +355,12 @@ export class Mysql extends DataSource {
|
|
|
358
355
|
const rows = await connection.query('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '`' + sql + sort + limit + offset, Object.values(values));
|
|
359
356
|
return Promise.all(rows.map(row => this.valuesFromDb(row, type)));
|
|
360
357
|
}
|
|
358
|
+
targetName(property) {
|
|
359
|
+
const type = property.type.type;
|
|
360
|
+
return (isAnyType(type) && depends.storeOf(type))
|
|
361
|
+
? property.name + 'Id'
|
|
362
|
+
: property.name;
|
|
363
|
+
}
|
|
361
364
|
async update(object) {
|
|
362
365
|
const connection = this.connection ?? await this.connect();
|
|
363
366
|
const [values, deferred] = await this.valuesToDb(object);
|
package/package.json
CHANGED