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

@saltcorn/db-common

Package Overview
Dependencies
Maintainers
2
Versions
310
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saltcorn/db-common - npm Package Compare versions

Comparing version 0.9.6-beta.0 to 0.9.6-beta.1

28

dist/sqlite-commons.d.ts

@@ -29,7 +29,7 @@ /**

/**
*
* @param tbl
* @param obj
* @param opts
* @returns
* Build a INSERT INTO sql statement for one row
* @param tbl table name
* @param obj row to insert
* @param opts noid, ignoreExisting, replace
* @returns sql string and values for the placeholders
*/

@@ -41,3 +41,20 @@ export declare const buildInsertSql: (tbl: string, obj: Row, opts?: {

}) => SqlAndValues;
declare type SqlAndValuesBulk = {
sql: string;
vals: string[];
};
/**
* Build INSERT INTO sql statements for multiple rows
* The rows are grouped by fields that are the same
* @param tbl table name
* @param objs rows to insert
* @param opts noid, ignoreExisting, replace
* @returns an array of sql strings with values for the placeholders
*/
export declare const buildInsertBulkSql: (tbl: string, objs: Row[], opts?: {
noid?: boolean;
ignoreExisting?: boolean;
replace?: boolean;
}) => Array<SqlAndValuesBulk>;
/**
*

@@ -89,2 +106,3 @@ * @param tbl

export declare const doListScTables: (queryFunc: any) => Promise<any>;
export {};
//# sourceMappingURL=sqlite-commons.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.doListScTables = exports.doListUserDefinedTables = exports.doListTables = exports.do_drop_index = exports.do_add_index = exports.doDeleteWhere = exports.doCount = exports.buildInsertSql = exports.mkVal = exports.reprAsJson = void 0;
exports.doListScTables = exports.doListUserDefinedTables = exports.doListTables = exports.do_drop_index = exports.do_add_index = exports.doDeleteWhere = exports.doCount = exports.buildInsertBulkSql = exports.buildInsertSql = exports.mkVal = exports.reprAsJson = void 0;
/**

@@ -26,7 +26,7 @@ * This is the sqlite-common module

/**
*
* @param tbl
* @param obj
* @param opts
* @returns
* Build a INSERT INTO sql statement for one row
* @param tbl table name
* @param obj row to insert
* @param opts noid, ignoreExisting, replace
* @returns sql string and values for the placeholders
*/

@@ -56,2 +56,41 @@ const buildInsertSql = (tbl, obj, opts = {}) => {

/**
* Build INSERT INTO sql statements for multiple rows
* The rows are grouped by fields that are the same
* @param tbl table name
* @param objs rows to insert
* @param opts noid, ignoreExisting, replace
* @returns an array of sql strings with values for the placeholders
*/
const buildInsertBulkSql = (tbl, objs, opts = {}) => {
const result = new Array();
const ignoreExisting = opts.ignoreExisting ? "or ignore" : "";
const replace = opts.replace ? "or replace" : "";
// group rows by fields that are the same
const fieldsWithRows = {};
for (const obj of objs) {
const kvs = Object.entries(obj);
const fnames = kvs.map(([k, v]) => `"${(0, internal_1.sqlsanitize)(k)}"`).join(",");
const vals = kvs
.filter(([k, v]) => !(v && v.next_version_by_id))
.map(exports.mkVal);
if (!fieldsWithRows[fnames])
fieldsWithRows[fnames] = {
valPattern: `(${kvs
.map(([k, v]) => ((0, exports.reprAsJson)(v) ? "json(?)" : "?"))
.join()})`,
vals: [],
count: 0,
};
fieldsWithRows[fnames].vals.push(...vals);
fieldsWithRows[fnames].count++;
}
for (const [k, v] of Object.entries(fieldsWithRows)) {
const { valPattern, vals, count } = v;
const sql = `insert ${ignoreExisting} ${replace} into "${(0, internal_1.sqlsanitize)(tbl)}" (${k}) values ${Array(count).fill(valPattern).join(",")}`;
result.push({ sql, vals });
}
return result;
};
exports.buildInsertBulkSql = buildInsertBulkSql;
/**
*

@@ -58,0 +97,0 @@ * @param tbl

2

package.json
{
"name": "@saltcorn/db-common",
"version": "0.9.6-beta.0",
"version": "0.9.6-beta.1",
"description": "Db common structures for Saltcorn, open-source no-code platform",

@@ -5,0 +5,0 @@ "homepage": "https://saltcorn.com",

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