@axiosleo/orm-mysql 0.10.2 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/orm-mysql.js +1 -1
- package/index.d.ts +12 -0
- package/package.json +1 -1
- package/src/migration.js +1 -1
- package/src/operator.js +7 -0
package/README.md
CHANGED
|
@@ -107,7 +107,7 @@ async function insertExample() {
|
|
|
107
107
|
|
|
108
108
|
// The insert operation will be changed to the update operation if the uuid already exists
|
|
109
109
|
row = await query.keys('uuid').insert({
|
|
110
|
-
uuid: 'uuid-string',
|
|
110
|
+
uuid: 'uuid-string', // uuid is unique index
|
|
111
111
|
name: "Joe",
|
|
112
112
|
age: 18,
|
|
113
113
|
})
|
package/bin/orm-mysql.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -245,6 +245,11 @@ export declare class QueryOperator extends Query {
|
|
|
245
245
|
upsertRow<T extends Object>(row: T, ...conditions: WhereItem[]): Promise<MySQLQueryResult>;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
export type TableInfoColumn = 'TABLE_CATALOG' | 'TABLE_SCHEMA' | 'TABLE_NAME' | 'COLUMN_NAME' | 'ORDINAL_POSITION' |
|
|
249
|
+
'COLUMN_DEFAULT' | 'IS_NULLABLE' | 'DATA_TYPE' | 'CHARACTER_MAXIMUM_LENGTH' | 'CHARACTER_OCTET_LENGTH' |
|
|
250
|
+
'NUMERIC_PRECISION' | 'NUMERIC_SCALE' | 'DATETIME_PRECISION' | 'CHARACTER_SET_NAME' | 'COLLATION_NAME' |
|
|
251
|
+
'COLUMN_TYPE' | 'COLUMN_KEY' | 'EXTRA' | 'PRIVILEGES' | 'COLUMN_COMMENT' | 'GENERATION_EXPRESSION' | 'SRS_ID';
|
|
252
|
+
|
|
248
253
|
export declare class QueryHandler {
|
|
249
254
|
conn: Connection | Pool;
|
|
250
255
|
options: QueryOperatorBaseOptions;
|
|
@@ -289,6 +294,13 @@ export declare class QueryHandler {
|
|
|
289
294
|
* @param database default is options.database
|
|
290
295
|
*/
|
|
291
296
|
existTable(table: string, database?: string): Promise<boolean>;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* @param database
|
|
300
|
+
* @param table
|
|
301
|
+
* @param attrs
|
|
302
|
+
*/
|
|
303
|
+
getTableFields<T extends Object>(database: string, table: string, ...attrs: TableInfoColumn[]): Promise<T>;
|
|
292
304
|
}
|
|
293
305
|
|
|
294
306
|
export declare class TransactionOperator extends QueryOperator {
|
package/package.json
CHANGED
package/src/migration.js
CHANGED
|
@@ -96,7 +96,7 @@ async function init(context) {
|
|
|
96
96
|
});
|
|
97
97
|
let res = await _execSQL(conn, builder.sql);
|
|
98
98
|
conn.end();
|
|
99
|
-
if (res.serverStatus !== 2) {
|
|
99
|
+
if (res.serverStatus !== 2 && res.serverStatus !== 16386) {
|
|
100
100
|
printer.error('create migration table failed.');
|
|
101
101
|
process.exit(1);
|
|
102
102
|
}
|
package/src/operator.js
CHANGED
|
@@ -224,6 +224,13 @@ class QueryHandler {
|
|
|
224
224
|
.count();
|
|
225
225
|
return !!c;
|
|
226
226
|
}
|
|
227
|
+
|
|
228
|
+
async getTableFields(database, table, ...attrs) {
|
|
229
|
+
return await this.query({
|
|
230
|
+
sql: `SELECT ${attrs.length ? '*' : attrs.join(',')} FROM information_schema.columns WHERE table_schema=? AND table_name=?`,
|
|
231
|
+
values: [database, table]
|
|
232
|
+
});
|
|
233
|
+
}
|
|
227
234
|
}
|
|
228
235
|
|
|
229
236
|
module.exports = {
|