extract-mysql-schema 0.7.6 → 0.7.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.
Files changed (2) hide show
  1. package/index.js +8 -30
  2. package/package.json +2 -6
package/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
- const SequelizeAdapter = require("sequelize");
3
- const orderBy = require("lodash.orderby");
2
+ const mysql = require('mysql2/promise');
4
3
 
5
4
  const spaceTabs = function(list) {
6
5
  const cols=[];
@@ -26,48 +25,29 @@ const spaceTabs = function(list) {
26
25
  return lines;
27
26
  }
28
27
 
29
-
30
- const getAdapter = async function (connection) {
31
- let adapter = new SequelizeAdapter(connection.database, connection.user, connection.password, {
32
- host: connection.Host,
33
- dialect: "mysql",
34
- logging: false,
35
- pool: {
36
- max: 5,
37
- min: 0,
38
- idle: 10000
39
- }
40
- });
41
- return adapter;
42
- }
43
-
44
28
  const extractSchemas = async function (connection, options) {
45
29
  const schemaName = connection.database;
46
30
  options = options || {};
47
31
 
48
- let adapter = await getAdapter(connection);
49
-
50
- let queryProcedures = await adapter.query(`
32
+ let c = await mysql.createConnection(connection);
33
+ let [queryProcedures] = await c.query(`
51
34
  SELECT * FROM INFORMATION_SCHEMA.ROUTINES where ROUTINE_SCHEMA = '${schemaName}'
52
35
  `);
53
- queryProcedures=queryProcedures[0];
54
36
 
55
- let queryParameters = await adapter.query(`
37
+ let [queryParameters] = await c.query(`
56
38
  SELECT p.* FROM INFORMATION_SCHEMA.PARAMETERS as p join INFORMATION_SCHEMA.ROUTINES as r on p.SPECIFIC_NAME=r.SPECIFIC_NAME and p.SPECIFIC_SCHEMA=r.ROUTINE_SCHEMA
57
39
  WHERE ROUTINE_SCHEMA='${schemaName}'
58
40
  ORDER BY p.SPECIFIC_NAME,p.ORDINAL_POSITION
59
41
  `);
60
- queryParameters=queryParameters[0];
61
42
 
62
- let queryFkey = await adapter.query(`
43
+ let [queryFkey] = await c.query(`
63
44
  SELECT iif.*, iifc.FOR_COL_NAME, iifc.REF_COL_NAME
64
45
  FROM INFORMATION_SCHEMA.INNODB_FOREIGN as iif
65
46
  JOIN INFORMATION_SCHEMA.INNODB_FOREIGN_COLS as iifc on iifc.ID=iif.ID
66
47
  WHERE iif.ID LIKE '${schemaName}/%'
67
48
  `);
68
- queryFkey=queryFkey[0];
69
49
 
70
- let queryIndexes = await adapter.query(`
50
+ let [queryIndexes] = await c.query(`
71
51
  select
72
52
  T2.TABLE_SCHEMA,T2.TABLE_NAME,I.NAME as INDEX_NAME,
73
53
  C.COLUMN_TYPE as FIELD_TYPE,
@@ -91,9 +71,8 @@ const extractSchemas = async function (connection, options) {
91
71
  WHERE T2.TABLE_SCHEMA = '${schemaName}' and F.POS=0
92
72
  ORDER BY T2.TABLE_SCHEMA,T2.TABLE_NAME,I.NAME,F.POS
93
73
  `);
94
- queryIndexes=queryIndexes[0];
95
74
 
96
- let queryColumns = await adapter.query(`
75
+ let [queryColumns] = await c.query(`
97
76
  SELECT T.TABLE_TYPE,C.*,
98
77
  CASE WHEN EXISTS(SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS C2 WHERE C2.TABLE_SCHEMA=C.TABLE_SCHEMA and C2.TABLE_NAME=C.TABLE_NAME AND C2.COLUMN_KEY='PRI' AND C.COLUMN_KEY='PRI' AND C2.COLUMN_NAME<>C.COLUMN_NAME) THEN 'YES' ELSE 'NO' END AS IS_COMPOUND_KEY
99
78
  ,TP.PARTITION_METHOD,TP.PARTITION_EXPRESSION
@@ -103,9 +82,8 @@ const extractSchemas = async function (connection, options) {
103
82
  where C.TABLE_SCHEMA ='${schemaName}'
104
83
  order by C.TABLE_NAME,C.ORDINAL_POSITION
105
84
  `);
106
- queryColumns = queryColumns[0];
107
85
 
108
- await adapter.close();
86
+ c.end();
109
87
 
110
88
  const foreign = {};
111
89
  for(let i=0;i<queryFkey.length;i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extract-mysql-schema",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": "./run.js",
@@ -18,10 +18,6 @@
18
18
  "author": "Chris Doty",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "mysql2": "^3.6.3",
22
- "sequelize": "^6.34.0"
23
- },
24
- "devDependencies": {
25
- "lodash.orderby": "^4.6.0"
21
+ "mysql2": "^3.9.3"
26
22
  }
27
23
  }