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

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,16 @@
1
1
  var generate_sql_from_object_default = {
2
+ select: (options = {}) => {
3
+ const column_names = Array.isArray(options?.columns) ? options?.columns?.join(",") : "*";
4
+ const whereEntries = Object.entries(options?.where);
5
+ const where = whereEntries?.map(([key], index) => {
6
+ return `${key} = $${index + 1}`;
7
+ })?.join(",");
8
+ return {
9
+ statement: `SELECT ${column_names} FROM ${options?.table} ${options?.where ? `WHERE ${where}` : ""}`,
10
+ column_names,
11
+ where
12
+ };
13
+ },
2
14
  insert: (options = {}) => {
3
15
  const column_names = Object.keys(options?.data)?.join(",");
4
16
  const value_placeholders = Object.keys(options?.data)?.map((_, index) => `$${index + 1}`)?.join(",");
@@ -48,6 +48,24 @@ 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) => {
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
+ },
51
69
  insert: (options = {}) => {
52
70
  const insert = generate_sql_from_object.insert(options);
53
71
  return pool.query(insert.statement, insert.values).then((response) => {
package/dist/app/index.js CHANGED
@@ -138,6 +138,7 @@ class App {
138
138
  postgresql: !hasMultipleOfProvider ? {
139
139
  ...postgresql?.pool,
140
140
  query: postgresql?.query,
141
+ select: postgresql?.select,
141
142
  insert: postgresql?.insert,
142
143
  update: postgresql?.update
143
144
  } : {
@@ -145,6 +146,7 @@ class App {
145
146
  [database?.settings?.name || `postgresql_${databasePort}`]: {
146
147
  ...postgresql?.pool,
147
148
  query: postgresql?.query,
149
+ select: postgresql?.select,
148
150
  insert: postgresql?.insert,
149
151
  update: postgresql?.update
150
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/node-canary",
3
- "version": "0.0.0-canary.309",
3
+ "version": "0.0.0-canary.310",
4
4
  "type": "module",
5
5
  "description": "A Node.js framework for building web apps.",
6
6
  "main": "./dist/index.js",