Skip to content

Commit

Permalink
finish first draft of a single interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Nov 2, 2023
1 parent 57af896 commit 5330571
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions cmd/tsutil-gen/templates/ts-rpcdb.ts.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,66 @@ export class {{ .Name }}s {
query: 'id=' + id,
}
}).then((res) => {
if (res.items.length == 0) {
reject(new Error("{{ .Name }} not found"))
return
}
resolve({{ .Name }}.fromJson(res.items[0]))
}).catch((err) => {
reject(err)
})
});
},

list(): Promise<{{ .Name }}[]>;
delete(id: string): Promise<void> {
return new Promise((resolve, reject) => {
this.client.query({
id: this.connID,
query: {
command: QueryRequest_QueryCommand.DELETE,
type: QueryRequest_QueryType.{{ .QueryType }},
query: 'id=' + id,
}
}).then(() => {
resolve()
}).catch((err) => {
reject(err)
})
});
},

list(): Promise<{{ .Name }}[]> {
return new Promise((resolve, reject) => {
this.client.query({
id: this.connID,
query: {
command: QueryRequest_QueryCommand.LIST,
type: QueryRequest_QueryType.{{ .QueryType }},
}
}).then((res) => {
resolve(res.items.map((item) => {{ .Name }}.fromJson(item)))
}).catch((err) => {
reject(err)
})
});
},

put(obj: {{ .Name }}): Promise<{{ .Name }}>;
put(obj: {{ .Name }}): Promise<void> {
return new Promise((resolve, reject) => {
this.client.query({
id: this.connID,
query: {
command: QueryRequest_QueryCommand.PUT,
type: QueryRequest_QueryType.{{ .QueryType }},
item: obj.toJson(),
}
}).then(() => {
resolve()
}).catch((err) => {
reject(err)
})
});
}

delete(id: string): Promise<void>;
}
{{- end }}

0 comments on commit 5330571

Please sign in to comment.