murmuration-postgresql 1.0.40 → 1.1.1

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/README.md CHANGED
@@ -35,7 +35,7 @@ const { database, migrate, transaction, Connection } = murmuration,
35
35
  ...
36
36
  ```
37
37
 
38
- This package leverages the [`pg`](https://node-postgres.com/) package and used its parameterised queries. This guard against SQL injection without further ado.
38
+ This package leverages the [`pg`](https://node-postgres.com/) package and uses its parameterised queries. This guard against SQL injection without further ado.
39
39
 
40
40
  ### Configuration
41
41
 
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ const { database, Statement: BaseStatement, caseUtilities } = require("murmuration");
4
+
5
+ const { query, execute: command } = database,
6
+ { camelCaseToSnakeCase, snakeCaseToCamelCase } = caseUtilities;
7
+
8
+ class Statement extends BaseStatement {
9
+ constructor(connection, sql, query, parameters, oneHandler, noneHandler, manyHandler, elseHandler, firstHandler, errorHandler, successHandler, placeholderIndex) {
10
+ super(connection, sql, query, parameters, oneHandler, noneHandler, manyHandler, elseHandler, firstHandler, errorHandler, successHandler);
11
+
12
+ this.placeholderIndex = placeholderIndex;
13
+ }
14
+
15
+ getPlaceholderIndex() {
16
+ return this.placeholderIndex;
17
+ }
18
+
19
+ update(relation) {
20
+ const sql = `UPDATE "${relation}"`;
21
+
22
+ this.setSQL(sql);
23
+
24
+ return this;
25
+ }
26
+
27
+ insertInto(relation) {
28
+ const sql = `INSERT INTO "${relation}"`;
29
+
30
+ this.setSQL(sql);
31
+
32
+ return this;
33
+ }
34
+
35
+ deleteFrom(relation) {
36
+ const sql = `DELETE FROM "${relation}"`;
37
+
38
+ this.setSQL(sql);
39
+
40
+ return this;
41
+ }
42
+
43
+ selectFrom(relation) {
44
+ const sql = `SELECT * FROM "${relation}"`;
45
+
46
+ this.setSQL(sql);
47
+
48
+ this.query = true;
49
+
50
+ return this;
51
+ }
52
+
53
+ placeholder() {
54
+ const placeholder = `\$${this.placeholderIndex}`;
55
+
56
+ this.placeholderIndex++;
57
+
58
+ return placeholder;
59
+ }
60
+
61
+ columnFromKey(key) {
62
+ const column = `"${camelCaseToSnakeCase(key)}"`;
63
+
64
+ return column;
65
+ }
66
+
67
+ keyFromColumn(column) {
68
+ const key = snakeCaseToCamelCase(column);
69
+
70
+ return key;
71
+ }
72
+
73
+ execute() {
74
+ const sql = this.getSQL(),
75
+ parameters = this.getParameters(),
76
+ connection = this.getConnection();
77
+
78
+ this.query ?
79
+ query(connection, sql, ...parameters, this.queryHandler) :
80
+ command(connection, sql, ...parameters, this.commandHandler);
81
+ }
82
+
83
+ static fromConnection(Class, connection) {
84
+ if (connection === undefined) {
85
+ connection = Class; ///
86
+
87
+ Class = Statement;
88
+ }
89
+
90
+ const sql = null,
91
+ query = false,
92
+ parameters = [],
93
+ oneHandler = null,
94
+ noneHandler = null,
95
+ manyHandler = null,
96
+ elseHandler = null,
97
+ firstHandler = null,
98
+ errorHandler = null,
99
+ successHandler = null,
100
+ placeholderIndex = 1,
101
+ statement = new Class(connection, sql, query, parameters, oneHandler, noneHandler, manyHandler, elseHandler, firstHandler, errorHandler, successHandler, placeholderIndex);
102
+
103
+ return statement;
104
+ }
105
+ }
106
+
107
+ module.exports = Statement;
package/bin/using.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ const Statement = require("./statement");
4
+
5
+ function using(connection) {
6
+ const statement = Statement.fromConnection(connection);
7
+
8
+ return statement;
9
+ }
10
+
11
+ module.exports = using;
package/index.js CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  const murmuration = require("murmuration");
4
4
 
5
- const migrate = require("./bin/migrate"),
5
+ const using = require("./bin/using"),
6
+ migrate = require("./bin/migrate"),
7
+ Statement = require("./bin/statement"),
6
8
  Connection = require("./bin/connection"),
7
9
  transaction = require("./bin/transaction");
8
10
 
@@ -10,7 +12,9 @@ const { database, CustomMigration } = murmuration;
10
12
 
11
13
  module.exports = {
12
14
  database,
15
+ using,
13
16
  migrate,
17
+ Statement,
14
18
  Connection,
15
19
  transaction,
16
20
  CustomMigration
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "murmuration-postgresql",
3
3
  "author": "James Smith",
4
- "version": "1.0.40",
4
+ "version": "1.1.1",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/murmuration-postgresql",
7
7
  "description": "Connections, transactions and migrations for PostgreSQL.",
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/djalbat/murmuration-postgresql"
11
11
  },
12
12
  "dependencies": {
13
- "murmuration": "^1.0.27",
13
+ "murmuration": "^1.1.1",
14
14
  "pg": "^8.3.3"
15
15
  },
16
16
  "devDependencies": {},