New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ORM for Notion Database? #391
Comments
I am having the same problem right now. The types are often not exported, the labels change etc. Some type of code generation would be ideal. |
I wrote this helper function here, where export const getPropertyUsingLabelToInferId = <T extends {[k: string]: {id: string}}, Label extends keyof T>(sample: T, value: unknown, label: Label): T[Label] => {
const name_to_id_mappings: Record<keyof T, string> =
Object.fromEntries(Object.entries(sample as {[k: string]: {id: string}}).map(([k,v]) => ([k, (v).id]))) as Record<keyof T, string>
const key = name_to_id_mappings[label]
const fields = Object.values(value as {[k: string]: {id: string}})
const field = fields.find(field => field.id === key)
if (!field) {
throw Error(`Field ${label.toString()}`)
}
return field as unknown as T[Label]
} |
👀 |
Will we ever have an ORM like Prisma for Notion Database?
The text was updated successfully, but these errors were encountered: