@galadrim/galadmin 0.1.130 → 0.1.132

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.
@@ -46,7 +46,7 @@ export default (column, record, config, onTable) => {
46
46
  } else if (column.dataType === "select" && column.options && column.options.constructor == Object) {
47
47
  return <div>{column.options[record[column.name]]}</div>
48
48
  } else if (column.dataType === "string[]") {
49
- return <div>{record[column.name].join(", ")}</div>
49
+ return <div>{record[column.name]?.join(", ")}</div>
50
50
  } else {
51
51
  return <div>{record[column.name]}</div>
52
52
  }
@@ -31,6 +31,42 @@ function convertQuery(mysqlQuery, params) {
31
31
  };
32
32
  }
33
33
 
34
+ function quotePostgresQuery(query) {
35
+ query = query.replace(/`/g, '"');
36
+
37
+ const reservedWords = ["1", "COUNT", "*", "UPDATE", "SELECT", "SET", "=", "INSERT", "DELETE", "FROM", "WHERE", "AND", "OR", "JOIN", "ON", "AS", "IN", "LIKE", "EXISTS", "ALL", "ANY", "NOT", "NULL", "TRUE", "FALSE", "GROUP", "BY", "ORDER", "LIMIT", "OFFSET", "DESC"]
38
+
39
+ const wordsToAddQuotes = new Set()
40
+ const parts = query.split(/[ \(\)]/);
41
+
42
+ let inString = false;
43
+
44
+ for (let i = 0; i < parts.length; i++) {
45
+ const part = parts[i].trim();
46
+ if (!part) {
47
+ continue
48
+ }
49
+ if (part.split(/['"]/).length % 2 === 0) {
50
+ inString = !inString;
51
+ }
52
+
53
+ if (inString || part.startsWith("$") || part.includes("'") || part.includes('"') || reservedWords.includes(part.toUpperCase())) {
54
+
55
+ } else {
56
+ for (let x of part.split(".")) {
57
+ wordsToAddQuotes.add(x)
58
+ }
59
+ }
60
+ }
61
+
62
+ let newQuery = query;
63
+ for (let word of wordsToAddQuotes) {
64
+ newQuery = newQuery.replace(new RegExp(`(?<!["\'])\\b${word}\\b(?!["\'])`, 'g'), `"${word}"`)
65
+ }
66
+
67
+ return newQuery;
68
+ }
69
+
34
70
  export default class dbManager {
35
71
  _db;
36
72
  dbType;
@@ -66,7 +102,7 @@ export default class dbManager {
66
102
  return new Promise((resolve, reject) => {
67
103
  if (this.dbType === "POSTGRESQL") {
68
104
  const result = convertQuery(queryString, args);
69
- queryString = result.pgQuery;
105
+ queryString = quotePostgresQuery(result.pgQuery);
70
106
  args = result.pgParams;
71
107
  }
72
108
  this._db.query(queryString, args, (a, b, c) => {