3.2.0 • Published 5 years ago

typed-mysql v3.2.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

typed-mysql

Uses schema-decorator to ensure the type-correctness of your MySQL queries.

Installation

npm install --save typed-mysql

Usage

import {Database} from "typed-mysql";
import * as sd from "schema-decorator";

class User {
    @sd.assert(sd.naturalNumber())
    id : number = 0;
    @sd.assert(sd.string())
    username : string = "";
}

async function main () {
    const db = new PooledDatabase({
        host     : Configuration.MysqlHost(),
        database : Configuration.MysqlDatabase(),
        charset  : Configuration.MysqlCharset(),
        user     : Configuration.MysqlUser(),
        password : Configuration.MysqlPassword(),
    });

    const user = await db.selectZeroOrOne(
        User,
        `
            SELECT
                id, username
            FROM
                user
            WHERE
                id = :id
        `,
        {
            id : id,
        }
    );
    console.log(user.id, user.username);
}
main()
    .catch((err) => {
        console.error(`Error in main()`, err);
        process.exit(1);
    });
3.2.0

5 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.6.2

6 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.13.0

6 years ago

1.12.0

6 years ago

1.11.0

6 years ago

1.10.0

6 years ago

1.9.1

6 years ago

1.9.0

6 years ago

1.8.2

6 years ago

1.8.1

6 years ago

1.8.0

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago