Updates
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
export type ExportMariaDBDatabaseParam = {
|
||||
dbFullName: string;
|
||||
targetFilePath: string;
|
||||
mariadbUser?: string;
|
||||
mariadbHost?: string;
|
||||
mariadbPass?: string;
|
||||
};
|
||||
export default function importMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }: ExportMariaDBDatabaseParam): Promise<string | Buffer<ArrayBufferLike>>;
|
||||
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = importMariadbDatabase;
|
||||
const child_process_1 = require("child_process");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
const conn_db_handler_1 = __importDefault(require("../db/conn-db-handler"));
|
||||
function importMariadbDatabase(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }) {
|
||||
const mysqlPath = os_1.default.platform().match(/win/i)
|
||||
? "'" +
|
||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysql.exe" +
|
||||
"'"
|
||||
: "mysql";
|
||||
const finalMariadbUser = mariadbUser || process.env.DSQL_DB_USERNAME;
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
yield (0, conn_db_handler_1.default)(global.DSQL_DB_CONN, `CREATE DATABASE IF NOT EXISTS ${dbFullName}`);
|
||||
const cmd = `${mysqlPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p${finalMariadbPass} ${dbFullName} < ${targetFilePath}`;
|
||||
let execSyncOptions = {
|
||||
encoding: "utf-8",
|
||||
};
|
||||
const importDb = (0, child_process_1.execSync)(cmd, execSyncOptions);
|
||||
return importDb;
|
||||
});
|
||||
}
|
||||
@@ -19,5 +19,7 @@ export default function grabDirNames(param?: Param): {
|
||||
userPrivateTempJSONSchemaFilePath: string | undefined;
|
||||
userPrivateDbExportZipFileName: string;
|
||||
userPrivateDbExportZipFilePath: string | undefined;
|
||||
userPrivateDbImportZipFileName: string;
|
||||
userPrivateDbImportZipFilePath: string | undefined;
|
||||
};
|
||||
export {};
|
||||
|
||||
@@ -15,7 +15,7 @@ function grabDirNames(param) {
|
||||
if (!schemasDir)
|
||||
throw new Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");
|
||||
const pakageSharedDir = path_1.default.join(appDir, `package-shared`);
|
||||
const mainDbTypeDefFile = path_1.default.join(appDir, `types/dsql.ts`);
|
||||
const mainDbTypeDefFile = path_1.default.join(pakageSharedDir, `types/dsql.ts`);
|
||||
const mainShemaJSONFilePath = path_1.default.join(schemasDir, `main.json`);
|
||||
const defaultTableFieldsJSONFilePath = path_1.default.join(pakageSharedDir, `data/defaultFields.json`);
|
||||
const usersSchemaDir = path_1.default.join(schemasDir, `users`);
|
||||
@@ -46,6 +46,10 @@ function grabDirNames(param) {
|
||||
const userPrivateDbExportZipFilePath = userPrivateSQLExportsDir
|
||||
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbExportZipFileName)
|
||||
: undefined;
|
||||
const userPrivateDbImportZipFileName = `db-export.zip`;
|
||||
const userPrivateDbImportZipFilePath = userPrivateSQLExportsDir
|
||||
? path_1.default.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
|
||||
: undefined;
|
||||
return {
|
||||
schemasDir,
|
||||
userDirPath,
|
||||
@@ -62,5 +66,7 @@ function grabDirNames(param) {
|
||||
userPrivateTempJSONSchemaFilePath,
|
||||
userPrivateDbExportZipFileName,
|
||||
userPrivateDbExportZipFilePath,
|
||||
userPrivateDbImportZipFileName,
|
||||
userPrivateDbImportZipFilePath,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
type Param = {
|
||||
str: string;
|
||||
userId: string | number;
|
||||
};
|
||||
export default function replaceDatasquirelDbName({ str, userId, }: Param): string;
|
||||
export {};
|
||||
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = replaceDatasquirelDbName;
|
||||
function replaceDatasquirelDbName({ str, userId, }) {
|
||||
const dbNamePrefix = process.env.DSQL_USER_DB_PREFIX;
|
||||
const userNameRegex = new RegExp(`${dbNamePrefix}\\d+_`, "g");
|
||||
const newPrefix = `${dbNamePrefix}${userId}_`;
|
||||
return str.replace(userNameRegex, newPrefix);
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
declare const consoleColors: {
|
||||
Reset: string;
|
||||
Bright: string;
|
||||
Dim: string;
|
||||
Underscore: string;
|
||||
Blink: string;
|
||||
Reverse: string;
|
||||
Hidden: string;
|
||||
FgBlack: string;
|
||||
FgRed: string;
|
||||
FgGreen: string;
|
||||
FgYellow: string;
|
||||
FgBlue: string;
|
||||
FgMagenta: string;
|
||||
FgCyan: string;
|
||||
FgWhite: string;
|
||||
FgGray: string;
|
||||
BgBlack: string;
|
||||
BgRed: string;
|
||||
BgGreen: string;
|
||||
BgYellow: string;
|
||||
BgBlue: string;
|
||||
BgMagenta: string;
|
||||
BgCyan: string;
|
||||
BgWhite: string;
|
||||
BgGray: string;
|
||||
};
|
||||
export default consoleColors;
|
||||
export declare const ccol: {
|
||||
Reset: string;
|
||||
Bright: string;
|
||||
Dim: string;
|
||||
Underscore: string;
|
||||
Blink: string;
|
||||
Reverse: string;
|
||||
Hidden: string;
|
||||
FgBlack: string;
|
||||
FgRed: string;
|
||||
FgGreen: string;
|
||||
FgYellow: string;
|
||||
FgBlue: string;
|
||||
FgMagenta: string;
|
||||
FgCyan: string;
|
||||
FgWhite: string;
|
||||
FgGray: string;
|
||||
BgBlack: string;
|
||||
BgRed: string;
|
||||
BgGreen: string;
|
||||
BgYellow: string;
|
||||
BgBlue: string;
|
||||
BgMagenta: string;
|
||||
BgCyan: string;
|
||||
BgWhite: string;
|
||||
BgGray: string;
|
||||
};
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ccol = void 0;
|
||||
const consoleColors = {
|
||||
Reset: "\x1b[0m",
|
||||
Bright: "\x1b[1m",
|
||||
Dim: "\x1b[2m",
|
||||
Underscore: "\x1b[4m",
|
||||
Blink: "\x1b[5m",
|
||||
Reverse: "\x1b[7m",
|
||||
Hidden: "\x1b[8m",
|
||||
FgBlack: "\x1b[30m",
|
||||
FgRed: "\x1b[31m",
|
||||
FgGreen: "\x1b[32m",
|
||||
FgYellow: "\x1b[33m",
|
||||
FgBlue: "\x1b[34m",
|
||||
FgMagenta: "\x1b[35m",
|
||||
FgCyan: "\x1b[36m",
|
||||
FgWhite: "\x1b[37m",
|
||||
FgGray: "\x1b[90m",
|
||||
BgBlack: "\x1b[40m",
|
||||
BgRed: "\x1b[41m",
|
||||
BgGreen: "\x1b[42m",
|
||||
BgYellow: "\x1b[43m",
|
||||
BgBlue: "\x1b[44m",
|
||||
BgMagenta: "\x1b[45m",
|
||||
BgCyan: "\x1b[46m",
|
||||
BgWhite: "\x1b[47m",
|
||||
BgGray: "\x1b[100m",
|
||||
};
|
||||
exports.default = consoleColors;
|
||||
exports.ccol = consoleColors;
|
||||
@@ -0,0 +1,25 @@
|
||||
declare const LogTypes: readonly ["error", "warning"];
|
||||
type Param = {
|
||||
/**
|
||||
* data to be logged.
|
||||
*/
|
||||
log: any;
|
||||
/**
|
||||
* Log Title. Could be name of function or name of variable
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* Label for the log
|
||||
*/
|
||||
label?: string;
|
||||
/**
|
||||
* Log type. `error` or `warning` or default
|
||||
*/
|
||||
type?: (typeof LogTypes)[number];
|
||||
/**
|
||||
* Whether to add a time stamp
|
||||
*/
|
||||
addTime?: boolean;
|
||||
};
|
||||
export default function debugLog({ log, label, title, type, addTime }: Param): void;
|
||||
export {};
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = debugLog;
|
||||
const console_colors_1 = require("../console-colors");
|
||||
const LogTypes = ["error", "warning"];
|
||||
function debugLog({ log, label, title, type, addTime }) {
|
||||
const logType = (() => {
|
||||
switch (type) {
|
||||
case "error":
|
||||
return console_colors_1.ccol.FgRed;
|
||||
case "warning":
|
||||
return console_colors_1.ccol.FgYellow;
|
||||
default:
|
||||
return console_colors_1.ccol.FgGreen;
|
||||
}
|
||||
})();
|
||||
let logTxt = `${logType}DEBUG${console_colors_1.ccol.Reset}:::`;
|
||||
const date = new Date();
|
||||
const time = date.toLocaleTimeString("en-US", {
|
||||
hour: "numeric",
|
||||
minute: "numeric",
|
||||
second: "numeric",
|
||||
hour12: true,
|
||||
});
|
||||
const logTime = `${date.toLocaleDateString()}][${time}`;
|
||||
if (addTime)
|
||||
logTxt = `${console_colors_1.ccol.BgWhite}[${logTime}]${console_colors_1.ccol.Reset} ` + logTxt;
|
||||
if (title)
|
||||
logTxt += `${console_colors_1.ccol.FgBlue}${title}${console_colors_1.ccol.Reset}::`;
|
||||
if (label)
|
||||
logTxt += `${console_colors_1.ccol.FgWhite}${console_colors_1.ccol.Bright}${label}${console_colors_1.ccol.Reset} =>`;
|
||||
console.log(logTxt, log);
|
||||
}
|
||||
Reference in New Issue
Block a user