0.4.4 • Published 4 months ago

mysql-oh-wait-utils v0.4.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Mysql-oh-wait-utils

Load your schema without coding any loading logic.

db-undump bin

Usage

Make sure to have schema.sql file in my-project/src/data/schema.sql (see example below). Also make sure to have the proper .env variables:

DB_HOST=localhost
DB_USER=some_username
DB_PASSWORD=users_password
DB_NAME=my_dbname

Finally execute the binary:

npx db-undump

Done! Have a look at your database, and it should have the new schema.

Example schema.sql file

SET foreign_key_checks = 0;
DROP TABLE IF EXISTS `User`;
CREATE TABLE IF NOT EXISTS `User` (
  `UUID` varchar(255) NOT NULL,
  `username` varchar(30) NOT NULL UNIQUE,
  `email` varchar(200) NOT NULL UNIQUE,
  `cryptedPassword` varchar(255) NOT NULL,
  `isLoginAllowed` boolean NOT NULL DEFAULT 0,
  PRIMARY KEY (`UUID`),
  UNIQUE(`username`),
  UNIQUE(`email`)
);

DROP TABLE IF EXISTS `User_Meta`;
CREATE TABLE IF NOT EXISTS `User_Meta` (
  `userUUID` varchar(255) NOT NULL,
  PRIMARY KEY (`userUUID`),
  FOREIGN KEY (`userUUID`)
    REFERENCES `User` (`UUID`)
    ON DELETE CASCADE
);

MysqlReq loader for di-why

From your usual src/loaders/index.ts you can import MysqlReq's generic loader:

import { mysqlReqLoader, mysqlReqLoggerLoader } from 'mysql-oh-wait-utils';

const loadDict = {
  mysqlReq: mysqlReqLoader,
  // optionally pass granular loggers (keys: 'mysqlReqLogger' | 'mysqlMultipleReqLogger')
  mysqlReqLogger: { instance: myLogger },
};

// logger can come from somwhere else
const di = new DiContainer({ load: injectionDict });

export default di;

Mysql undumpSchema

You can set and .env var PROJECT_ROOT_DIR_ABS_PATH, it will try to load ${PROJECT_ROOT_DIR_ABS_PATH}/src/data/SCHEMA.sql

Otherwise it will use node_modules and try to figure out the root dir of the project.

0.3.0

4 months ago

0.2.1

4 months ago

0.4.4

4 months ago

0.4.1

4 months ago

0.2.2

4 months ago

0.4.3

4 months ago

0.4.2

4 months ago

0.2.0

1 year ago

0.1.3

2 years ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.2

3 years ago

0.0.1

3 years ago