@cdutils/supermodel
v1.18.0
Published
MySQL object modelling framework
Downloads
37
Readme
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.