const db = new DatabaseConfig();
db.addConnection({
'driver' : 'sqlite',
'database': ':memory:'
});
db.bootFedaco();
db.setAsGlobal();
@Table({
tableName: 'user'
})
class User extends Model {
@PrimaryColumn
id;
@Column()
email;
@Column()
name;
@Column()
age;
@CreatedAtColumn()
created_at;
@UpdateAtColumn()
updated_at;
}
const list = await User.createQuery().get();
const schemaBuilder = Model.getConnectionResolver()
.connection(connectionName)
.getSchemaBuilder();
;
await schemaBuilder().create('users', table => {
table.increments('id');
table.string('email').withUnique();
table.string('name');
table.string('age');
});
ecma class with field declaration not in constructor is not support. es2016 is support but es2022 is not.
field declaration can use declare
keyword to declare field in constructor, then the field will not generated in class when enabled es2022
like this
@Table({
tableName: 'user'
})
class User extends Model {
@PrimaryColumn()
declare id;
}