Mysql Dump
Create a backup of a MySQL database.
Installation
yarn add @assignar/mysqldump
// or
npm install @assignar/mysqldump
Usage
import mysqldump from '@assignar/mysqldump'
mysqldump({
connection: {
host: 'localhost',
user: 'root',
password: '123456',
database: 'my_database',
},
dumpToFile: './dump.sql',
})
const result = await mysqldump({
connection: {
host: 'localhost',
user: 'root',
password: '123456',
database: 'my_database',
},
})
Options
All the below options are documented in the typescript declaration file:
export interface ConnectionOptions {
host?: string;
port?: number;
database: string;
user: string;
password: string;
charset?: string;
}
export interface SchemaDumpOptions {
autoIncrement?: boolean;
engine?: boolean;
format?: boolean;
table?: {
ifNotExist?: boolean;
dropIfExist?: boolean;
charset?: boolean | string;
};
view?: {
createOrReplace?: boolean;
definer?: boolean;
algorithm?: boolean;
sqlSecurity?: boolean;
};
}
export interface TriggerDumpOptions {
delimiter?: string | false;
dropIfExist?: boolean;
definer?: boolean;
}
export interface DataDumpOptions {
format?: boolean;
includeViewData?: boolean;
maxRowsPerInsertStatement?: number;
returnFromFunction?: boolean;
where?: {
[k: string]: string;
};
}
export interface DumpOptions {
tables?: string[];
excludeTables?: boolean;
schema?: false | SchemaDumpOptions;
data?: false | DataDumpOptions;
trigger?: false | TriggerDumpOptions;
}
export interface Options {
connection: ConnectionOptions;
dump?: DumpOptions;
dumpToFile?: string;
}
export interface ColumnList {
[k: string]: {
type: string;
nullable: boolean;
};
}
export interface Table {
name: string;
schema: string | null;
data: string | null;
columns: ColumnList;
columnsOrdered: string[];
isView: boolean;
triggers: string[];
}
export interface DumpReturn {
dump: {
schema: string | null;
data: string | null;
trigger: string | null;
};
tables: Table[];
}
export default function main(inputOptions: Options): Promise<DumpReturn>;
export as namespace mysqldump;
The MIT License
Contributing
Installation
Make sure to first install all the required development dependencies:
yarn
// or
npm install .
Linting
We use eslint in conjunction with typescript-eslint-parser for code linting.
PRs are required to pass the linting with no errors and preferrably no warnings.
Testing
Tests can be run via the test
script - yarn test
/ npm test
.
Additionally it's required that you do a build and run your test against the public package to ensure the build doesn't cause regressions - yarn run test-prod
/ npm run test-prod
.
PRs are required to maintain the 100% test coverage, and all tests must pass successfully.