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

db-knife

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-knife - npm Package Compare versions

Comparing version 0.0.9 to 1.0.0

.github/workflows/test-and-release.yml

45

dist/index.js

@@ -1,2 +0,1 @@

#!/usr/bin/env node
"use strict";

@@ -59,11 +58,4 @@ var __assign = (this && this.__assign) || function () {

var arg_1 = __importDefault(require("arg"));
var DBUtils_1 = require("./DBUtils/DBUtils");
function applyTemplate(_a) {
var template = _a.template, args = _a.args;
var argKeys = Object.keys(args);
return argKeys.reduce(function (str, argKey) {
var r = new RegExp("{{" + argKey + "}}", 'g');
return str.replace(r, args[argKey]);
}, template);
}
var utils_1 = require("./utils");
var template_1 = require("./utils/template");
function getDBName(file) {

@@ -75,6 +67,6 @@ var name = path_1["default"].dirname(file).split(path_1["default"].sep).pop();

var sqlFiles = _a.sqlFiles, db = _a.db, template = _a.template;
var dbUtils = new DBUtils_1.DBUtils(db);
var dbUtils = new utils_1.DBUtils(db);
var dbIdentifier = dbUtils.getDBIdentifier();
var defaultTemplate = dbUtils.getDefaultTemplate(dbIdentifier, template);
var templateCommands = DBUtils_1.DBUtils.getTemplateCommands();
var templateCommands = utils_1.DBUtils.getTemplateCommands();
var customTemplate = Boolean(template)

@@ -90,3 +82,3 @@ ? templateCommands.reduce(function (acc, command) {

.map(function (sqlFile) {
return applyTemplate({
return template_1.applyTemplate({
template: useTemplate,

@@ -99,20 +91,11 @@ args: __assign(__assign({}, dbFlags), { db_user: dbTokens.username, db_pass: dbTokens.password, db_host: dbTokens.host, db_name: getDBName(sqlFile), db_schema: dbIdentifier === 'postgres' ? 'public' : '', file_path: sqlFile })

exports.produceScripts = produceScripts;
function getRelevantFiles(importData, importDataOnly) {
if (importDataOnly) {
return function (f) {
return ['data_generated.sql', 'data.sql'].some(function (file) { return f.includes(file); });
};
}
function getRelevantFiles(importData) {
if (!importData) {
return function (f) { return f.includes('schema.sql'); };
}
return function (f) {
return ['schema.sql', 'data_generated.sql', 'data.sql'].some(function (file) {
return f.includes(file);
});
};
return function (f) { return f.includes('schema.sql') || f.includes('data_generated.sql'); };
}
function main() {
return __awaiter(this, void 0, void 0, function () {
var args, folder, folderPath, subFoldersArg, subFolders, db, template, importData, importDataOnly, sqlFiles, scripts;
var args, folder, folderPath, subFoldersArg, subFolders, db, template, importData, sqlFiles, scripts;
return __generator(this, function (_a) {

@@ -124,4 +107,3 @@ args = arg_1["default"]({

'--template': String,
'--data': Boolean,
'--data-only': Boolean
'--data': Boolean
});

@@ -156,5 +138,3 @@ folder = args['--folder'];

importData = args['--data'] || false;
importDataOnly = args['--data-only'] || false;
sqlFiles = subFolders
.flatMap(function (folder) {
sqlFiles = subFolders.flatMap(function (folder) {
var files = fs_1["default"]

@@ -168,7 +148,4 @@ .readdirSync(folder)

else {
return files.filter(getRelevantFiles(importData, importDataOnly));
return files.filter(getRelevantFiles(importData));
}
})
.sort(function (f1, f2) {
return path_1["default"].basename(f1) > path_1["default"].basename(f2) ? -1 : 1;
});

@@ -175,0 +152,0 @@ scripts = produceScripts({ sqlFiles: sqlFiles, db: db, template: template }).join(os_1["default"].EOL);

{
"name": "db-knife",
"version": "0.0.9",
"version": "1.0.0",
"main": "dist/index.js",

@@ -10,2 +10,3 @@ "bin": {

"dependencies": {
"@pimeys/connection-string": "0.1.10",
"arg": "4.1.3",

@@ -18,2 +19,3 @@ "connection-string-parser": "1.0.3"

"jest": "26.4.2",
"semantic-release": "17.3.0",
"ts-jest": "26.3.0",

@@ -26,4 +28,5 @@ "ts-node": "9.0.0",

"prepublish": "yarn build",
"test": "jest"
"test": "jest",
"release": "semantic-release"
}
}
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