@hackthedev/dsync-sql 1.0.5 → 1.0.6
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/index.mjs +21 -21
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -73,7 +73,7 @@ export default class dSyncSql {
|
|
|
73
73
|
|
|
74
74
|
try {
|
|
75
75
|
connection = await this.pool.getConnection();
|
|
76
|
-
const [results
|
|
76
|
+
const [results] = await connection.execute(query, params);
|
|
77
77
|
return results;
|
|
78
78
|
} catch (err) {
|
|
79
79
|
if (err.code === 'ER_LOCK_DEADLOCK' && retryCount > 0) {
|
|
@@ -138,33 +138,33 @@ export default class dSyncSql {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
async createTable(table) {
|
|
141
|
-
const
|
|
141
|
+
const columns = [...table.columns];
|
|
142
|
+
|
|
143
|
+
if (table.keys) {
|
|
144
|
+
for (const key of table.keys) {
|
|
145
|
+
columns.push(`${key.name} ${key.type}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const columnsDefinition = columns
|
|
150
|
+
.map(col => typeof col === "string" ? col : `${col.name} ${col.type}`)
|
|
151
|
+
.join(", ");
|
|
152
|
+
|
|
142
153
|
const createTableQuery = mysql.format(
|
|
143
154
|
`
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
155
|
+
CREATE TABLE ??
|
|
156
|
+
(
|
|
157
|
+
${columnsDefinition}
|
|
158
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
|
159
|
+
`,
|
|
149
160
|
[table.name]
|
|
150
161
|
);
|
|
151
162
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
await this.queryDatabase(createTableQuery);
|
|
155
|
-
|
|
156
|
-
console.log(`Table "${table.name}" created successfully.`);
|
|
157
|
-
if (table.keys) {
|
|
158
|
-
await this.addKeys(table);
|
|
159
|
-
}
|
|
160
|
-
if (table.autoIncrement) {
|
|
161
|
-
await this.addAutoIncrement(table);
|
|
162
|
-
}
|
|
163
|
-
} catch (err) {
|
|
164
|
-
Logger.error('Error in createTable:', err);
|
|
165
|
-
}
|
|
163
|
+
console.log("Executing CREATE TABLE query:", createTableQuery);
|
|
164
|
+
await this.queryDatabase(createTableQuery);
|
|
166
165
|
}
|
|
167
166
|
|
|
167
|
+
|
|
168
168
|
async addMissingColumns(tableName, columns) {
|
|
169
169
|
const alter = columns
|
|
170
170
|
.map(col => `ADD COLUMN ${col.name} ${col.type}`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackthedev/dsync-sql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "dSyncSql is supposed to be a helper for handling MySQL / MariaDB connections and executing queries. In addition it will also allow you to automatically create a database's structure like tables, column and such and will automatically create missing columns and tables based off a json Object.",
|
|
5
5
|
"homepage": "https://github.com/NETWORK-Z-Dev/dSyncSql#readme",
|
|
6
6
|
"bugs": {
|