Bugfix
This commit is contained in:
parent
a2961d6b89
commit
95318307fe
@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
// @ts-check
|
||||
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) {
|
||||
@ -27,8 +26,7 @@ function apiGet(_a) {
|
||||
query,
|
||||
values: queryValues,
|
||||
});
|
||||
if (typeof query == "string" &&
|
||||
query.match(/^alter|^delete|information_schema|databases|^create/i)) {
|
||||
if (typeof query == "string" && query.match(/^alter|^delete|^create/i)) {
|
||||
return { success: false, msg: "Wrong Input." };
|
||||
}
|
||||
let results;
|
||||
|
@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = createDbFromSchema;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const noDatabaseDbHandler_1 = __importDefault(require("./utils/noDatabaseDbHandler"));
|
||||
const varDatabaseDbHandler_1 = __importDefault(require("./utils/varDatabaseDbHandler"));
|
||||
@ -21,6 +20,7 @@ const createTable_1 = __importDefault(require("./utils/createTable"));
|
||||
const updateTable_1 = __importDefault(require("./utils/updateTable"));
|
||||
const dbHandler_1 = __importDefault(require("./utils/dbHandler"));
|
||||
const ejson_1 = __importDefault(require("../utils/ejson"));
|
||||
const grab_dir_names_1 = __importDefault(require("@/utils/backend/names/grab-dir-names"));
|
||||
/**
|
||||
* # Create database from Schema Function
|
||||
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||
@ -28,9 +28,10 @@ const ejson_1 = __importDefault(require("../utils/ejson"));
|
||||
function createDbFromSchema(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ userId, targetDatabase, dbSchemaData, }) {
|
||||
var _b, _c;
|
||||
const schemaPath = userId
|
||||
? path_1.default.join(String(process.env.DSQL_USER_DB_SCHEMA_PATH), `/user-${userId}/main.json`)
|
||||
: path_1.default.resolve(__dirname, "../../jsonData/dbSchemas/main.json");
|
||||
const { userSchemaMainJSONFilePath, mainShemaJSONFilePath } = (0, grab_dir_names_1.default)({
|
||||
userId,
|
||||
});
|
||||
const schemaPath = userSchemaMainJSONFilePath || mainShemaJSONFilePath;
|
||||
const dbSchema = dbSchemaData ||
|
||||
ejson_1.default.parse(fs_1.default.readFileSync(schemaPath, "utf8"));
|
||||
if (!dbSchema) {
|
||||
|
8
dist/package-shared/utils/backend/export-mariadb-database.d.ts
vendored
Normal file
8
dist/package-shared/utils/backend/export-mariadb-database.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
export type ExportMariaDBDatabaseParam = {
|
||||
dbFullName: string;
|
||||
targetFilePath: string;
|
||||
mariadbUser?: string;
|
||||
mariadbHost?: string;
|
||||
mariadbPass?: string;
|
||||
};
|
||||
export default function exportMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }: ExportMariaDBDatabaseParam): string | Buffer<ArrayBufferLike>;
|
24
dist/package-shared/utils/backend/export-mariadb-database.js
vendored
Normal file
24
dist/package-shared/utils/backend/export-mariadb-database.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = exportMariadbDatabase;
|
||||
const child_process_1 = require("child_process");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
function exportMariadbDatabase({ dbFullName, targetFilePath, mariadbHost, mariadbPass, mariadbUser, }) {
|
||||
const mysqlDumpPath = os_1.default.platform().match(/win/i)
|
||||
? "'" +
|
||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
||||
"'"
|
||||
: "mysqldump";
|
||||
const finalMariadbUser = mariadbUser || process.env.DSQL_DB_USERNAME;
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
const cmd = `${mysqlDumpPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p${finalMariadbPass} ${dbFullName} > ${targetFilePath}`;
|
||||
let execSyncOptions = {
|
||||
encoding: "utf-8",
|
||||
};
|
||||
const dumpDb = (0, child_process_1.execSync)(cmd, execSyncOptions);
|
||||
return dumpDb;
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
import _ from "lodash";
|
||||
import serverError from "../../backend/serverError";
|
||||
import runQuery, { DbContextsArray } from "../../backend/db/runQuery";
|
||||
@ -7,7 +5,6 @@ import {
|
||||
ApiGetQueryObject,
|
||||
DSQL_TableSchemaType,
|
||||
GetReturn,
|
||||
ServerQueryParam,
|
||||
} from "../../../types";
|
||||
import apiGetGrabQueryAndValues from "../../../utils/grab-query-and-values";
|
||||
|
||||
@ -40,10 +37,7 @@ export default async function apiGet<
|
||||
values: queryValues,
|
||||
});
|
||||
|
||||
if (
|
||||
typeof query == "string" &&
|
||||
query.match(/^alter|^delete|information_schema|databases|^create/i)
|
||||
) {
|
||||
if (typeof query == "string" && query.match(/^alter|^delete|^create/i)) {
|
||||
return { success: false, msg: "Wrong Input." };
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import updateTable from "./utils/updateTable";
|
||||
import dbHandler from "./utils/dbHandler";
|
||||
import EJSON from "../utils/ejson";
|
||||
import { DSQL_DatabaseSchemaType } from "../types";
|
||||
import grabDirNames from "@/utils/backend/names/grab-dir-names";
|
||||
|
||||
type Param = {
|
||||
userId?: number | string | null;
|
||||
@ -24,12 +25,11 @@ export default async function createDbFromSchema({
|
||||
targetDatabase,
|
||||
dbSchemaData,
|
||||
}: Param) {
|
||||
const schemaPath = userId
|
||||
? path.join(
|
||||
String(process.env.DSQL_USER_DB_SCHEMA_PATH),
|
||||
`/user-${userId}/main.json`
|
||||
)
|
||||
: path.resolve(__dirname, "../../jsonData/dbSchemas/main.json");
|
||||
const { userSchemaMainJSONFilePath, mainShemaJSONFilePath } = grabDirNames({
|
||||
userId,
|
||||
});
|
||||
|
||||
const schemaPath = userSchemaMainJSONFilePath || mainShemaJSONFilePath;
|
||||
|
||||
const dbSchema: DSQL_DatabaseSchemaType[] | undefined =
|
||||
dbSchemaData ||
|
||||
|
38
package-shared/utils/backend/export-mariadb-database.ts
Normal file
38
package-shared/utils/backend/export-mariadb-database.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { execSync, ExecSyncOptions } from "child_process";
|
||||
import os from "os";
|
||||
|
||||
export type ExportMariaDBDatabaseParam = {
|
||||
dbFullName: string;
|
||||
targetFilePath: string;
|
||||
mariadbUser?: string;
|
||||
mariadbHost?: string;
|
||||
mariadbPass?: string;
|
||||
};
|
||||
|
||||
export default function exportMariadbDatabase({
|
||||
dbFullName,
|
||||
targetFilePath,
|
||||
mariadbHost,
|
||||
mariadbPass,
|
||||
mariadbUser,
|
||||
}: ExportMariaDBDatabaseParam) {
|
||||
const mysqlDumpPath = os.platform().match(/win/i)
|
||||
? "'" +
|
||||
"C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" +
|
||||
"'"
|
||||
: "mysqldump";
|
||||
|
||||
const finalMariadbUser = mariadbUser || process.env.DSQL_DB_USERNAME;
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
|
||||
const cmd = `${mysqlDumpPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p${finalMariadbPass} ${dbFullName} > ${targetFilePath}`;
|
||||
|
||||
let execSyncOptions: ExecSyncOptions = {
|
||||
encoding: "utf-8",
|
||||
};
|
||||
|
||||
const dumpDb = execSync(cmd, execSyncOptions);
|
||||
|
||||
return dumpDb;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "4.0.4",
|
||||
"version": "4.0.5",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
Loading…
Reference in New Issue
Block a user