@hackthedev/dsync-sql 1.0.4 → 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.
Files changed (2) hide show
  1. package/index.mjs +25 -25
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -41,10 +41,10 @@ export default class dSyncSql {
41
41
  if(!outFile) throw new Error('Output File path is required');
42
42
  return await new Promise((resolve, reject) => {
43
43
  const dump = spawn("mariadb-dump", [
44
- "-h", this.host,
45
- "-u", this.user,
46
- `-p${this.password}`,
47
- this.database
44
+ "-h", this.connection_info.host,
45
+ "-u", this.connection_info.user,
46
+ `-p${this.connection_info.password}`,
47
+ this.connection_info.database
48
48
  ]);
49
49
 
50
50
  const stream = fs.createWriteStream(outFile);
@@ -73,7 +73,7 @@ export default class dSyncSql {
73
73
 
74
74
  try {
75
75
  connection = await this.pool.getConnection();
76
- const [results,] = await connection.execute(query, params);
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 columnsDefinition = table.columns.map(col => `${col.name} ${col.type}`).join(', ');
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
- CREATE TABLE ??
145
- (
146
- ${columnsDefinition}
147
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE =utf8mb4_general_ci
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
- try {
153
- console.log('Executing CREATE TABLE query:', createTableQuery);
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.4",
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": {