@joystick.js/node-canary 0.0.0-canary.310 → 0.0.0-canary.312
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.
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
var generate_sql_from_object_default = {
|
|
2
|
+
create_table: (options = {}) => {
|
|
3
|
+
const columns = Object.entries(options?.columns)?.map(([column_name, column_type]) => {
|
|
4
|
+
return `${column_name} ${column_type}`;
|
|
5
|
+
})?.join(",");
|
|
6
|
+
return {
|
|
7
|
+
statement: `CREATE TABLE IF NOT EXISTS ${options?.table} (${columns})`,
|
|
8
|
+
columns
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
add_column: (options = {}) => {
|
|
12
|
+
return {
|
|
13
|
+
statement: `ALTER TABLE ${options?.table} ADD COLUMN IF NOT EXISTS ${options?.column_name} ${options?.column_type}`
|
|
14
|
+
};
|
|
15
|
+
},
|
|
2
16
|
select: (options = {}) => {
|
|
3
17
|
const column_names = Array.isArray(options?.columns) ? options?.columns?.join(",") : "*";
|
|
4
18
|
const whereEntries = Object.entries(options?.where);
|
|
@@ -31,38 +31,44 @@ var postgresql_default = async (settings = {}, databasePort = 2610) => {
|
|
|
31
31
|
const pool = new Pool(connection_config);
|
|
32
32
|
return {
|
|
33
33
|
pool,
|
|
34
|
-
query: (...
|
|
35
|
-
return pool.query(...
|
|
34
|
+
query: (...args) => {
|
|
35
|
+
return pool.query(...args).then((response) => {
|
|
36
36
|
return response?.rows || [];
|
|
37
37
|
}).catch((error) => {
|
|
38
38
|
console.log(chalk.redBright(`
|
|
39
39
|
Failed SQL Statement:
|
|
40
40
|
`));
|
|
41
|
-
console.log(
|
|
41
|
+
console.log(args[0]);
|
|
42
42
|
console.log(`
|
|
43
43
|
`);
|
|
44
44
|
console.log(chalk.redBright(`
|
|
45
45
|
Failed Values:
|
|
46
46
|
`));
|
|
47
|
-
console.log(
|
|
47
|
+
console.log(args[1]);
|
|
48
48
|
throw error;
|
|
49
49
|
});
|
|
50
50
|
},
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
return pool.query(
|
|
51
|
+
add_column: (options = {}) => {
|
|
52
|
+
const column = generate_sql_from_object.add_column(options);
|
|
53
|
+
return pool.query(column.statement).then((response) => {
|
|
54
54
|
return response?.rows || [];
|
|
55
55
|
}).catch((error) => {
|
|
56
56
|
console.log(chalk.redBright(`
|
|
57
57
|
Failed SQL Statement:
|
|
58
58
|
`));
|
|
59
|
-
console.log(
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
console.log(column.statement);
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
create_table: (options = {}) => {
|
|
64
|
+
const table = generate_sql_from_object.create_table(options);
|
|
65
|
+
return pool.query(table.statement).then((response) => {
|
|
66
|
+
return response?.rows || [];
|
|
67
|
+
}).catch((error) => {
|
|
62
68
|
console.log(chalk.redBright(`
|
|
63
|
-
Failed
|
|
69
|
+
Failed SQL Statement:
|
|
64
70
|
`));
|
|
65
|
-
console.log(
|
|
71
|
+
console.log(table.statement);
|
|
66
72
|
throw error;
|
|
67
73
|
});
|
|
68
74
|
},
|
|
@@ -74,13 +80,31 @@ Failed Values:
|
|
|
74
80
|
console.log(chalk.redBright(`
|
|
75
81
|
Failed SQL Statement:
|
|
76
82
|
`));
|
|
77
|
-
console.log(
|
|
83
|
+
console.log(insert.statement);
|
|
78
84
|
console.log(`
|
|
79
85
|
`);
|
|
80
86
|
console.log(chalk.redBright(`
|
|
81
87
|
Failed Values:
|
|
82
88
|
`));
|
|
83
|
-
console.log(
|
|
89
|
+
console.log(insert.values);
|
|
90
|
+
throw error;
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
select: (options = {}) => {
|
|
94
|
+
const select = generate_sql_from_object.select(options);
|
|
95
|
+
return pool.query(select.statement, select.where).then((response) => {
|
|
96
|
+
return response?.rows || [];
|
|
97
|
+
}).catch((error) => {
|
|
98
|
+
console.log(chalk.redBright(`
|
|
99
|
+
Failed SQL Statement:
|
|
100
|
+
`));
|
|
101
|
+
console.log(select.statement);
|
|
102
|
+
console.log(`
|
|
103
|
+
`);
|
|
104
|
+
console.log(chalk.redBright(`
|
|
105
|
+
Failed Values:
|
|
106
|
+
`));
|
|
107
|
+
console.log(select.where);
|
|
84
108
|
throw error;
|
|
85
109
|
});
|
|
86
110
|
},
|
|
@@ -92,13 +116,13 @@ Failed Values:
|
|
|
92
116
|
console.log(chalk.redBright(`
|
|
93
117
|
Failed SQL Statement:
|
|
94
118
|
`));
|
|
95
|
-
console.log(
|
|
119
|
+
console.log(update.statement);
|
|
96
120
|
console.log(`
|
|
97
121
|
`);
|
|
98
122
|
console.log(chalk.redBright(`
|
|
99
123
|
Failed Values:
|
|
100
124
|
`));
|
|
101
|
-
console.log(
|
|
125
|
+
console.log(update.values);
|
|
102
126
|
throw error;
|
|
103
127
|
});
|
|
104
128
|
}
|
package/dist/app/index.js
CHANGED
|
@@ -137,17 +137,21 @@ class App {
|
|
|
137
137
|
...process.databases || {},
|
|
138
138
|
postgresql: !hasMultipleOfProvider ? {
|
|
139
139
|
...postgresql?.pool,
|
|
140
|
+
add_column: postgresql?.add_column,
|
|
141
|
+
create_table: postgresql?.create_table,
|
|
142
|
+
insert: postgresql?.insert,
|
|
140
143
|
query: postgresql?.query,
|
|
141
144
|
select: postgresql?.select,
|
|
142
|
-
insert: postgresql?.insert,
|
|
143
145
|
update: postgresql?.update
|
|
144
146
|
} : {
|
|
145
147
|
...process?.databases?.postgresql || {},
|
|
146
148
|
[database?.settings?.name || `postgresql_${databasePort}`]: {
|
|
147
149
|
...postgresql?.pool,
|
|
150
|
+
add_column: postgresql?.add_column,
|
|
151
|
+
create_table: postgresql?.create_table,
|
|
152
|
+
insert: postgresql?.insert,
|
|
148
153
|
query: postgresql?.query,
|
|
149
154
|
select: postgresql?.select,
|
|
150
|
-
insert: postgresql?.insert,
|
|
151
155
|
update: postgresql?.update
|
|
152
156
|
}
|
|
153
157
|
}
|