How to implement interface for table?

Say I have an interface of User
interface User {
id: string,
name: string,
age: number
}
interface User {
id: string,
name: string,
age: number
}
and this is how I declare my schema
export const user = pgTable("user", {
id: serial("id"),
name: text("name"),
age: integer("age"
});
export const user = pgTable("user", {
id: serial("id"),
name: text("name"),
age: integer("age"
});
How do I make sure that the user table implement the User interface that I have declared?
4 Replies
ArwanceR
ArwanceRā€¢15mo ago
Why do it the other way? You can first declare schema and be it your interface with
type User = InferModel<typeof user>
type User = InferModel<typeof user>
šŸ‡ØšŸ‡­ Marko Bolliger <cannap>
maybe he has shared interface for client and server
nqhtrung
nqhtrungā€¢15mo ago
This, Iā€™m working in a monorepo where I have a module for Web, one for API and one for shared interface. The workflow is I first create an interface in the shared interface module then use it in both web and api modules. This way I can make sure the api returns the correct type for the web.
gmaclennan
gmaclennanā€¢15mo ago
@nqhtrung I'm not sure if this is what you are looking for, but the types in here might be helpful for you: https://github.com/digidem/mapeo-core-next/blob/981070acfd22ca68d4537f666749bccc5ef033dc/lib/schema/schema-to-drizzle.js (they might not be completely correct - this is an in-progress PR)
GitHub
mapeo-core-next/lib/schema/schema-to-drizzle.js at 981070acfd22ca68...
The upcoming version of Mapeo Core. Contribute to digidem/mapeo-core-next development by creating an account on GitHub.
Want results from more Discord servers?
Add your server