@joystick.js/node-canary 0.0.0-canary.310 → 0.0.0-canary.311

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);
@@ -48,9 +48,27 @@ Failed Values:
48
48
  throw error;
49
49
  });
50
50
  },
51
- select: (options = {}) => {
52
- const select = generate_sql_from_object.select(options);
53
- return pool.query(select.statement, select.where).then((response) => {
51
+ add_column: (options = {}) => {
52
+ const column = generate_sql_from_object.add_column(options);
53
+ return pool.query(column.statement).then((response) => {
54
+ return response?.rows || [];
55
+ }).catch((error) => {
56
+ console.log(chalk.redBright(`
57
+ Failed SQL Statement:
58
+ `));
59
+ console.log(args[0]);
60
+ console.log(`
61
+ `);
62
+ console.log(chalk.redBright(`
63
+ Failed Values:
64
+ `));
65
+ console.log(args[1]);
66
+ throw error;
67
+ });
68
+ },
69
+ create_table: (options = {}) => {
70
+ const table = generate_sql_from_object.create_table(options);
71
+ return pool.query(table.statement).then((response) => {
54
72
  return response?.rows || [];
55
73
  }).catch((error) => {
56
74
  console.log(chalk.redBright(`
@@ -79,6 +97,24 @@ Failed SQL Statement:
79
97
  `);
80
98
  console.log(chalk.redBright(`
81
99
  Failed Values:
100
+ `));
101
+ console.log(args[1]);
102
+ throw error;
103
+ });
104
+ },
105
+ select: (options = {}) => {
106
+ const select = generate_sql_from_object.select(options);
107
+ return pool.query(select.statement, select.where).then((response) => {
108
+ return response?.rows || [];
109
+ }).catch((error) => {
110
+ console.log(chalk.redBright(`
111
+ Failed SQL Statement:
112
+ `));
113
+ console.log(args[0]);
114
+ console.log(`
115
+ `);
116
+ console.log(chalk.redBright(`
117
+ Failed Values:
82
118
  `));
83
119
  console.log(args[1]);
84
120
  throw error;
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.310",
3
+ "version": "0.0.0-canary.311",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",