@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 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
@@ -9,7 +9,7 @@ const app = new App({
9
9
  name: 'MySQL ORM CLI',
10
10
  desc: 'migrate, model, seed, etc.',
11
11
  bin: 'orm-mysql',
12
- version: '0.10.2',
12
+ version: '0.10.4',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
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 = {