43 lines
998 B
TypeScript
43 lines
998 B
TypeScript
import { Data } from '../../app/data'
|
|
import { Entity } from '../../app/entity'
|
|
import { RepoSQLite } from '../../app/repo/sqlite'
|
|
import { StorageSQLite } from '../../app/storage/sqlite'
|
|
import { Storage } from '../../app/storage'
|
|
|
|
export class ItemData extends Data {
|
|
uniqKey(): string {
|
|
return 'uid'
|
|
}
|
|
|
|
uid: string
|
|
title: string
|
|
}
|
|
export class ItemEntity extends Entity<ItemData> {
|
|
_getRepo(storage: Storage): ItemsRepo {
|
|
return new ItemsRepo(storage)
|
|
}
|
|
|
|
_getVO(): ItemData {
|
|
return new ItemData()
|
|
}
|
|
}
|
|
export class ItemsRepo extends RepoSQLite<ItemEntity> {
|
|
Entity(): ItemEntity {
|
|
return new ItemEntity()
|
|
}
|
|
|
|
Name(): string {
|
|
return 'items'
|
|
}
|
|
|
|
async Create(): Promise<void> {
|
|
const st = this._storage as StorageSQLite
|
|
await st?.db?.run(`
|
|
create table if not exists ${this.Name()} (
|
|
uid varchar(255) not null unique,
|
|
title text null
|
|
)
|
|
`)
|
|
}
|
|
}
|