pqb 0.11.24 → 0.11.26

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
@@ -2,4 +2,4 @@
2
2
 
3
3
  A query builder for Postgres database focused on type safety with TypeScript.
4
4
 
5
- [Read docs here](https://orchid-orm.netlify.app/guide/query-builder-setup.html).
5
+ [Read docs here](https://orchid-orm.netlify.app/guide/orm-and-query-builder.html).
package/dist/index.js CHANGED
@@ -124,7 +124,7 @@ class ColumnType extends orchidCore.ColumnTypeBase {
124
124
  }
125
125
  }
126
126
 
127
- const keys = [];
127
+ const used = [];
128
128
  const getRaw = (raw, valuesArray) => {
129
129
  if (!raw.__values) {
130
130
  return raw.__raw;
@@ -132,21 +132,29 @@ const getRaw = (raw, valuesArray) => {
132
132
  const arr = raw.__raw.split("'");
133
133
  const values = raw.__values;
134
134
  const len = arr.length;
135
- keys.length = 0;
135
+ used.length = 0;
136
136
  for (let i = 0; i < len; i += 2) {
137
- arr[i] = arr[i].replace(/\$(\w+)/g, (_, key) => {
137
+ arr[i] = arr[i].replace(/\$\$?(\w+)/g, (match, key) => {
138
138
  const value = values[key];
139
139
  if (value === void 0) {
140
140
  throw new Error(`Query variable \`${key}\` is not provided`);
141
141
  }
142
- keys.push(key);
142
+ used.push(key);
143
+ if (match.length - key.length === 2) {
144
+ if (typeof value !== "string") {
145
+ throw new Error(
146
+ `Expected string value for $$${key} SQL keyword, got ${typeof value}`
147
+ );
148
+ }
149
+ return `"${value.replace('"', '""').replace(".", '"."')}"`;
150
+ }
143
151
  valuesArray.push(value);
144
152
  return `$${valuesArray.length}`;
145
153
  });
146
154
  }
147
- if (keys.length > 0 && keys.length < Object.keys(values).length) {
155
+ if (used.length > 0 && used.length < Object.keys(values).length) {
148
156
  for (const key in values) {
149
- if (!keys.includes(key)) {
157
+ if (!used.includes(key)) {
150
158
  throw new Error(`Query variable \`${key}\` is unused`);
151
159
  }
152
160
  }