-
Notifications
You must be signed in to change notification settings - Fork 1
/
7.ts
40 lines (34 loc) · 786 Bytes
/
7.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
interface BaseEntity {
id:number;
created_at:Date;
updated_at:Date;
}
interface Raw {
sql:string;
}
type Rawify<T> = {[key in keyof T]:T[key]|Raw}
class BaseStore<E> {
async insert(...data:Partial<Rawify<E>>[]):Promise<number> {
return 1;
}
async getMany<T extends keyof E>(cond:Partial<Rawify<E>>, ...fields:T[]):Promise<Pick<E, T>[]> {
return [];
}
}
// test code
interface UserEntity extends BaseEntity {
username:string;
password:string;
}
class UserStore extends BaseStore<UserEntity> { }
async () => {
const userStore = new UserStore();
const insertId = await userStore.insert({
id: {sql: '1+1'},
username: 'erona',
})
const result = await userStore.getMany({
username: 'neko',
password: 'cat',
}, 'id', 'username')
}