@cdutils/supermodel
TypeScript icon, indicating that this package has built-in type declarations

1.18.0 • Public • Published

SuperModel

It's simple...

1. Connect to the database

const connection: DatabaseConnection = new DatabaseConnection({
    hostname: '...',
    user: '...',
    password: '...',
    database: '...'
});

2. Define a model

@ModelClass('account', connection)
class Account extends Model {

    public async getUsername(): Promise<string> {
        return this.get<string>('username');
    }

    public setUsername(username: string): void {
        return this.set('username', username);
    }

}

3. Insert an item to the table

const account: Account = new Account({
    username: 'johndoe'
});
await account.save();

4. Fetch an item from the table

const account: Account = await Account
    .findOne()
    .where('username').isLike('johndoe')
    .exec();
console.log('We found: ' + await account.getUsername());

That's all there is to it.

Readme

Keywords

none

Package Sidebar

Install

npm i @cdutils/supermodel

Weekly Downloads

0

Version

1.18.0

License

MIT

Unpacked Size

71.5 kB

Total Files

18

Last publish

Collaborators

  • connerdouglass