Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

af-db-ts

Package Overview
Dependencies
Maintainers
0
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

af-db-ts - npm Package Compare versions

Comparing version 3.0.5 to 3.0.6

5

dist/cjs/src/pg/get-sql/insert.js

@@ -11,4 +11,5 @@ "use strict";

const tableSchema = await (0, table_schema_pg_1.getTableSchemaPg)(arg.connectionId, commonSchemaAndTable);
const { columnsSchema, fieldsWoSerialsAndRO, defaults } = tableSchema;
const insertFieldsArray = fieldsWoSerialsAndRO.filter((f) => (!(arg.excludeFromInsert || []).includes(f)));
const { columnsSchema, fieldsWoRO, fieldsWoSerialsAndRO, defaults } = tableSchema;
const insertFieldsListPre = arg.keepSerialFields ? fieldsWoRO : fieldsWoSerialsAndRO;
const insertFieldsArray = insertFieldsListPre.filter((f) => (!(arg.excludeFromInsert || []).includes(f)));
const insertFieldsList = insertFieldsArray.map((f) => `"${f}"`).join(', ');

@@ -15,0 +16,0 @@ const preparedRowsArray = arg.recordset.map((record) => {

11

dist/cjs/src/pg/get-sql/reset-sequence.js

@@ -10,5 +10,10 @@ "use strict";

const { serialsFields } = await (0, table_schema_pg_1.getTableSchemaPg)(arg.connectionId, commonSchemaAndTable);
return serialsFields.map((incFName) => {
const sequenceName = `${table}_${incFName}_seq`;
return `SELECT setval('"${schema}"."${sequenceName}"', (SELECT COALESCE(MAX("${incFName}"), 1) FROM "${schema}"."${table}"));`;
// eslint-disable-next-line arrow-body-style
return serialsFields.map((serialFieldName) => {
return `SELECT setval(
pg_get_serial_sequence('"${schema}"."${table}"', '${serialFieldName}'),
(SELECT COALESCE(MAX("${serialFieldName}"), 1) FROM "${schema}"."${table}")
);`;
// const sequenceName = `${table}_${serialFieldName}_seq`;
// return `SELECT setval('"${schema}"."${sequenceName}"', (SELECT COALESCE(MAX("${serialFieldName}"), 1) FROM "${schema}"."${table}"));`;
}).join('\n');

@@ -15,0 +20,0 @@ };

@@ -147,5 +147,6 @@ "use strict";

const readOnlyFields = Object.values(columnsSchema).filter((s) => s.readOnly).map((s) => s.name);
const fieldsWoRO = fieldsArray.filter((f) => !readOnlyFields.includes(f));
const fieldsWoSerialsAndRO = fieldsArray.filter((f) => !serialsFields.includes(f) && !readOnlyFields.includes(f));
tableSchema = {
columnsSchema, pk, uc, defaults, serialsFields, fieldsArray, fieldsWoSerialsAndRO, readOnlyFields,
columnsSchema, pk, uc, defaults, serialsFields, fieldsArray, fieldsWoRO, fieldsWoSerialsAndRO, readOnlyFields,
};

@@ -152,0 +153,0 @@ tableSchemaHash[commonSchemaAndTable] = tableSchema;

@@ -8,4 +8,5 @@ import { getTableSchemaPg } from '../table-schema-pg';

const tableSchema = await getTableSchemaPg(arg.connectionId, commonSchemaAndTable);
const { columnsSchema, fieldsWoSerialsAndRO, defaults } = tableSchema;
const insertFieldsArray = fieldsWoSerialsAndRO.filter((f) => (!(arg.excludeFromInsert || []).includes(f)));
const { columnsSchema, fieldsWoRO, fieldsWoSerialsAndRO, defaults } = tableSchema;
const insertFieldsListPre = arg.keepSerialFields ? fieldsWoRO : fieldsWoSerialsAndRO;
const insertFieldsArray = insertFieldsListPre.filter((f) => (!(arg.excludeFromInsert || []).includes(f)));
const insertFieldsList = insertFieldsArray.map((f) => `"${f}"`).join(', ');

@@ -12,0 +13,0 @@ const preparedRowsArray = arg.recordset.map((record) => {

@@ -7,7 +7,12 @@ import { getTableSchemaPg } from '../table-schema-pg';

const { serialsFields } = await getTableSchemaPg(arg.connectionId, commonSchemaAndTable);
return serialsFields.map((incFName) => {
const sequenceName = `${table}_${incFName}_seq`;
return `SELECT setval('"${schema}"."${sequenceName}"', (SELECT COALESCE(MAX("${incFName}"), 1) FROM "${schema}"."${table}"));`;
// eslint-disable-next-line arrow-body-style
return serialsFields.map((serialFieldName) => {
return `SELECT setval(
pg_get_serial_sequence('"${schema}"."${table}"', '${serialFieldName}'),
(SELECT COALESCE(MAX("${serialFieldName}"), 1) FROM "${schema}"."${table}")
);`;
// const sequenceName = `${table}_${serialFieldName}_seq`;
// return `SELECT setval('"${schema}"."${sequenceName}"', (SELECT COALESCE(MAX("${serialFieldName}"), 1) FROM "${schema}"."${table}"));`;
}).join('\n');
};
//# sourceMappingURL=reset-sequence.js.map

@@ -144,5 +144,6 @@ // noinspection SqlResolve

const readOnlyFields = Object.values(columnsSchema).filter((s) => s.readOnly).map((s) => s.name);
const fieldsWoRO = fieldsArray.filter((f) => !readOnlyFields.includes(f));
const fieldsWoSerialsAndRO = fieldsArray.filter((f) => !serialsFields.includes(f) && !readOnlyFields.includes(f));
tableSchema = {
columnsSchema, pk, uc, defaults, serialsFields, fieldsArray, fieldsWoSerialsAndRO, readOnlyFields,
columnsSchema, pk, uc, defaults, serialsFields, fieldsArray, fieldsWoRO, fieldsWoSerialsAndRO, readOnlyFields,
};

@@ -149,0 +150,0 @@ tableSchemaHash[commonSchemaAndTable] = tableSchema;

@@ -24,2 +24,3 @@ import { Pool, PoolClient } from 'pg';

readOnlyFields: TFieldName[];
fieldsWoRO: TFieldName[];
fieldsWoSerialsAndRO: TFieldName[];

@@ -26,0 +27,0 @@ }

@@ -9,3 +9,4 @@ import { TDBRecord, TRecordSet } from '../../@types/i-common';

isErrorOnConflict?: boolean;
keepSerialFields?: boolean;
}) => Promise<string>;
//# sourceMappingURL=insert.d.ts.map
{
"name": "af-db-ts",
"version": "3.0.5",
"version": "3.0.6",
"description": "A highly specialized function library",

@@ -5,0 +5,0 @@ "main": "./dist/cjs/src/index.js",

@@ -26,2 +26,3 @@ import { Pool, PoolClient } from 'pg';

readOnlyFields: TFieldName[], // массив имен полей ReadOnly
fieldsWoRO: TFieldName[], // массив имен полей без полей ReadOnly
fieldsWoSerialsAndRO: TFieldName[], // массив имен полей без полей identity и ReadOnly

@@ -28,0 +29,0 @@ }

@@ -15,2 +15,3 @@ import { getTableSchemaPg } from '../table-schema-pg';

isErrorOnConflict?: boolean,
keepSerialFields?: boolean,
}): Promise<string> => {

@@ -20,5 +21,6 @@ const { commonSchemaAndTable } = arg;

const tableSchema: ITableSchemaPg = await getTableSchemaPg(arg.connectionId, commonSchemaAndTable);
const { columnsSchema, fieldsWoSerialsAndRO, defaults } = tableSchema;
const { columnsSchema, fieldsWoRO, fieldsWoSerialsAndRO, defaults } = tableSchema;
const insertFieldsArray = fieldsWoSerialsAndRO.filter((f) => (!(arg.excludeFromInsert || []).includes(f)));
const insertFieldsListPre = arg.keepSerialFields ? fieldsWoRO : fieldsWoSerialsAndRO;
const insertFieldsArray = insertFieldsListPre.filter((f) => (!(arg.excludeFromInsert || []).includes(f)));
const insertFieldsList = insertFieldsArray.map((f) => `"${f}"`).join(', ');

@@ -25,0 +27,0 @@

@@ -13,6 +13,11 @@ import { getTableSchemaPg } from '../table-schema-pg';

return serialsFields.map((incFName) => {
const sequenceName = `${table}_${incFName}_seq`;
return `SELECT setval('"${schema}"."${sequenceName}"', (SELECT COALESCE(MAX("${incFName}"), 1) FROM "${schema}"."${table}"));`;
// eslint-disable-next-line arrow-body-style
return serialsFields.map((serialFieldName) => {
return `SELECT setval(
pg_get_serial_sequence('"${schema}"."${table}"', '${serialFieldName}'),
(SELECT COALESCE(MAX("${serialFieldName}"), 1) FROM "${schema}"."${table}")
);`;
// const sequenceName = `${table}_${serialFieldName}_seq`;
// return `SELECT setval('"${schema}"."${sequenceName}"', (SELECT COALESCE(MAX("${serialFieldName}"), 1) FROM "${schema}"."${table}"));`;
}).join('\n');
};

@@ -155,6 +155,7 @@ // noinspection SqlResolve

const readOnlyFields: string[] = Object.values(columnsSchema).filter((s) => s.readOnly).map((s) => s.name as string);
const fieldsWoRO: string[] = fieldsArray.filter((f) => !readOnlyFields.includes(f));
const fieldsWoSerialsAndRO: string[] = fieldsArray.filter((f) => !serialsFields.includes(f) && !readOnlyFields.includes(f));
tableSchema = {
columnsSchema, pk, uc, defaults, serialsFields, fieldsArray, fieldsWoSerialsAndRO, readOnlyFields,
columnsSchema, pk, uc, defaults, serialsFields, fieldsArray, fieldsWoRO, fieldsWoSerialsAndRO, readOnlyFields,
};

@@ -161,0 +162,0 @@ tableSchemaHash[commonSchemaAndTable] = tableSchema;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc