@or-sdk/pgsql 1.0.3-beta.1920.0 → 1.0.3-beta.1935.0

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.
Files changed (60) hide show
  1. package/dist/cjs/Pgsql.js +35 -122
  2. package/dist/cjs/Pgsql.js.map +1 -1
  3. package/dist/cjs/utils/encodeValue.js +17 -0
  4. package/dist/cjs/utils/encodeValue.js.map +1 -0
  5. package/dist/cjs/utils/extractDatabaseNames.js +10 -0
  6. package/dist/cjs/utils/extractDatabaseNames.js.map +1 -0
  7. package/dist/cjs/utils/getDeleteRowsQuery.js +9 -0
  8. package/dist/cjs/utils/getDeleteRowsQuery.js.map +1 -0
  9. package/dist/cjs/utils/getEditRowQuery.js +10 -0
  10. package/dist/cjs/utils/getEditRowQuery.js.map +1 -0
  11. package/dist/cjs/utils/getInsertKeys.js +9 -0
  12. package/dist/cjs/utils/getInsertKeys.js.map +1 -0
  13. package/dist/cjs/utils/getInsertQueries.js +18 -0
  14. package/dist/cjs/utils/getInsertQueries.js.map +1 -0
  15. package/dist/cjs/utils/index.js +13 -1
  16. package/dist/cjs/utils/index.js.map +1 -1
  17. package/dist/esm/Pgsql.js +28 -101
  18. package/dist/esm/Pgsql.js.map +1 -1
  19. package/dist/esm/utils/encodeValue.js +12 -0
  20. package/dist/esm/utils/encodeValue.js.map +1 -0
  21. package/dist/esm/utils/extractDatabaseNames.js +5 -0
  22. package/dist/esm/utils/extractDatabaseNames.js.map +1 -0
  23. package/dist/esm/utils/getDeleteRowsQuery.js +8 -0
  24. package/dist/esm/utils/getDeleteRowsQuery.js.map +1 -0
  25. package/dist/esm/utils/getEditRowQuery.js +10 -0
  26. package/dist/esm/utils/getEditRowQuery.js.map +1 -0
  27. package/dist/esm/utils/getInsertKeys.js +7 -0
  28. package/dist/esm/utils/getInsertKeys.js.map +1 -0
  29. package/dist/esm/utils/getInsertQueries.js +14 -0
  30. package/dist/esm/utils/getInsertQueries.js.map +1 -0
  31. package/dist/esm/utils/index.js +6 -0
  32. package/dist/esm/utils/index.js.map +1 -1
  33. package/dist/types/Pgsql.d.ts +17 -27
  34. package/dist/types/Pgsql.d.ts.map +1 -1
  35. package/dist/types/types.d.ts +5 -19
  36. package/dist/types/types.d.ts.map +1 -1
  37. package/dist/types/utils/encodeValue.d.ts +4 -0
  38. package/dist/types/utils/encodeValue.d.ts.map +1 -0
  39. package/dist/types/utils/extractDatabaseNames.d.ts +4 -0
  40. package/dist/types/utils/extractDatabaseNames.d.ts.map +1 -0
  41. package/dist/types/utils/getDeleteRowsQuery.d.ts +4 -0
  42. package/dist/types/utils/getDeleteRowsQuery.d.ts.map +1 -0
  43. package/dist/types/utils/getEditRowQuery.d.ts +4 -0
  44. package/dist/types/utils/getEditRowQuery.d.ts.map +1 -0
  45. package/dist/types/utils/getInsertKeys.d.ts +4 -0
  46. package/dist/types/utils/getInsertKeys.d.ts.map +1 -0
  47. package/dist/types/utils/getInsertQueries.d.ts +4 -0
  48. package/dist/types/utils/getInsertQueries.d.ts.map +1 -0
  49. package/dist/types/utils/index.d.ts +6 -0
  50. package/dist/types/utils/index.d.ts.map +1 -1
  51. package/package.json +2 -2
  52. package/src/Pgsql.ts +56 -143
  53. package/src/types.ts +9 -19
  54. package/src/utils/encodeValue.ts +11 -0
  55. package/src/utils/extractDatabaseNames.ts +7 -0
  56. package/src/utils/getDeleteRowsQuery.ts +10 -0
  57. package/src/utils/getEditRowQuery.ts +12 -0
  58. package/src/utils/getInsertKeys.ts +9 -0
  59. package/src/utils/getInsertQueries.ts +18 -0
  60. package/src/utils/index.ts +6 -0
@@ -0,0 +1,11 @@
1
+ import { EncodedValue } from '../types';
2
+ import _ from 'lodash';
3
+
4
+ function encodeValue(value: unknown): EncodedValue {
5
+ if (_.isUndefined(value) || value === '' || _.isNull(value)) return 'NULL';
6
+ if (_.isString(value)) return `'${value.replaceAll('\'', '\'\'')}'`;
7
+ if (_.isNumber(value) || _.isBoolean(value)) return value;
8
+ return `'${JSON.stringify(value).replaceAll('\'', '\'\'')}'`;
9
+ }
10
+
11
+ export default encodeValue;
@@ -0,0 +1,7 @@
1
+ import { ListDatabasesResponseItem } from '../types';
2
+
3
+ function extractDatabaseNames(databaseNameArr: ListDatabasesResponseItem[]): string[] {
4
+ return databaseNameArr.map(({ name }) => name);
5
+ }
6
+
7
+ export default extractDatabaseNames;
@@ -0,0 +1,10 @@
1
+ import { Row } from '../types';
2
+ import { encodeValue, splitPrimaryKeys } from '../utils';
3
+
4
+ function getDeleteRowQuery(schema: string, table: string, rows: Row[], primaryKeys: string): string {
5
+ const pk = splitPrimaryKeys(primaryKeys);
6
+ return `delete from ${schema}.${table}
7
+ where (${rows.map(row => `${pk.map(primaryKey => `${primaryKey} = ${encodeValue(row[primaryKey])}`).join(' AND ')}`).join(') \nOR (')})`;
8
+ }
9
+
10
+ export default getDeleteRowQuery;
@@ -0,0 +1,12 @@
1
+ import { encodeValue, splitPrimaryKeys } from '../utils';
2
+ import { Row } from '../types';
3
+
4
+ function getEditRowQuery(schema: string, table: string, key: string, value: unknown, row: Row, primaryKeys: string): string {
5
+ value = encodeValue(value);
6
+ const pk = splitPrimaryKeys(primaryKeys);
7
+ return `update ${schema}.${table}
8
+ set ${key} = ${value}
9
+ where ${pk.map(primaryKey => `${primaryKey} = ${encodeValue(row[primaryKey])}`).join(' AND ')}`;
10
+ }
11
+
12
+ export default getEditRowQuery;
@@ -0,0 +1,9 @@
1
+ import { Row } from '../types';
2
+
3
+ function getInsertKeys(rows: Row[]): string[] {
4
+ const allKeys = {};
5
+ rows.forEach(x => Object.assign(allKeys, x));
6
+ return Object.keys(allKeys);
7
+ }
8
+
9
+ export default getInsertKeys;
@@ -0,0 +1,18 @@
1
+ import { Row } from '../types';
2
+ import { encodeValue, getInsertKeys } from '../utils';
3
+ import _ from 'lodash';
4
+
5
+ function getInsertQueries(schema: string, table: string, insertRows: Row[], chunkSize: number): string[] {
6
+ const rows = _.isArray(insertRows) ? insertRows : [insertRows];
7
+
8
+ const keys = getInsertKeys(rows);
9
+ const stringifyRow = (row: Row) => `${keys.map(key => encodeValue(row[key])).join(', ')}`;
10
+
11
+ return _.chain(rows)
12
+ .chunk(chunkSize)
13
+ .map((chunk) => `insert into ${schema}.${table} (${keys.join(', ')})
14
+ values (${chunk.map(stringifyRow).join('), (')});`)
15
+ .value();
16
+ }
17
+
18
+ export default getInsertQueries;
@@ -2,6 +2,9 @@
2
2
  * @internal
3
3
  */
4
4
 
5
+ export { default as extractDatabaseNames } from './extractDatabaseNames';
6
+ export { default as getInsertKeys } from './getInsertKeys';
7
+ export { default as encodeValue } from './encodeValue';
5
8
  export { default as splitPrimaryKeys } from './splitPrimaryKeys';
6
9
  export { default as getListTablesQuery } from './getListTablesQuery';
7
10
  export { default as createSchemaQuery } from './createSchemaQuery';
@@ -9,7 +12,10 @@ export { default as getDropSchemaQuery } from './getDropSchemaQuery';
9
12
  export { default as getCreateTableQuery } from './getCreateTableQuery';
10
13
  export { default as getDropTableQuery } from './getDropTableQuery';
11
14
  export { default as getAddColumnsQuery } from './getAddColumnsQuery';
15
+ export { default as getInsertQueries } from './getInsertQueries';
12
16
  export { default as getSelectAllCountQuery } from './getSelectAllCountQuery';
13
17
  export { default as getSelectAllQuery } from './getSelectAllQuery';
18
+ export { default as getEditRowQuery } from './getEditRowQuery';
19
+ export { default as getDeleteRowsQuery } from './getDeleteRowsQuery';
14
20
  export { default as getGenerateTableSchemaQuery } from './getGenerateTableSchemaQuery';
15
21
  export { default as getGetPrimaryKeysQuery } from './getGetPrimaryKeysQuery';