support table & index schema?
mattkrick opened this issue · comments
Matt Krick commented
Love the driver! Thank you so much for the work you've put into it.
Are you opposed to a way to instantiate r
so we could pass in a type schema? I'm looking for a way to get type information automatically without having to inject it into every query.
Rough idea:
// changes to driver types
table<T extends keyof Tables>(tableName: RValue<T>): RTable<Tables[T]>
// user code
interface IUser {
name: string
}
interface Tables {
User: IUser
}
const r = new R<Tables, Indexes>()
r.table('Foo') // error! Foo isn't a table
r.table('User').update({name: 1}) // error! name should be a string
await r.table('User').run() // returns IUser[]
I'm sure there are some gotchas since the tableName
could be a function, but I figure it'd be a nice little check that works for most use cases
Taimuraz Kaitmazov commented
Closing this issue due to #46 (comment)