0.1.7 • Published 5 years ago

mysql-dbc-table v0.1.7

Weekly downloads
92
License
-
Repository
-
Last release
5 years ago

mysql-dbc-table

creating and manipulating MySQL table by inheriting parent class with mysl-dbc

Install

npm install mysql-dbc-table

Usage Sample

Init mysql db connection

const mysql_dbc_table = require('./mysql-dbc-table');

// default:  mysql://root:@localhost:3306/test
const dbc = mysql_dbc_table.initDbc();

// custom: mysql://${user}:${password}@${host}:${port}/${database}
const dbc1 = mysql_dbc_table.initDbc({
    host: 'localhost',
    port: 3306,
    user: 'developer',
    password: 'my_password',
    database: 'my_database',
});

Perform SQL

const sql_create_table = `
    CREATE TABLE \`user\` (
      \`id\` int(11) NOT NULL AUTO_INCREMENT,
      \`name\` varchar(64) NOT NULL,
      \`created_time\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
      \`modified_time\` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      \`deleted\` boolean DEFAULT false,
      PRIMARY KEY (\`id\`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
`;

const step0 = await mysql_dbc_table.dbSqlAsync(dbc, sql_create_table);

Use data model with DbTable

const DbTable = mysql_dbc_table.DbTable;
class User extends DbTable {
    static fields() {
        return {
            id: {fmt: parseInt},
            name: {fmt: String, default: ''},
            created_time: {fmt: (...args) => new Date(...args)},
            modified_time: {fmt: (...args) => new Date(...args)},
            deleted: {fmt: Boolean, default: false},
        }
    }
}

const db_user = new User('user', dbc);
const existed = await db_user.existAsync();

const users = await db_user.findAsync();
const user = await db_user.findOneAsync();
更多请参阅 test.js
0.1.7

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

0.2.3-b

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.0

5 years ago

0.1.6

6 years ago

0.1.4

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago