You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The GetEntityItem and DeleteEntityItem types are additions for the already existing Create and Update types:
typeGetEntityItem<EextendsEntity<any,any,any,any>>=EextendsEntity<infer A, infer F, infer C, infer S>
? AllTableIndexCompositeAttributes<A,F,C,S>
: never;asyncfunctiongetTask(key: GetEntityItem<typeoftasks>){const{ data }=awaittasks.get(key).go();returndata;}typeDeleteEntityItem<EextendsEntity<any,any,any,any>>=EextendsEntity<
infer A,
infer F,
infer C,
infer S>
? AllTableIndexCompositeAttributes<A,F,C,S>
: never;asyncfunctiondeleteTask(key: DeleteEntityItem<typeoftasks>){awaittasks.delete(key).go();}
The QueryIndex type extracts the allowed keys of the different query operations:
typeQueryIndex<EextendsEntity<any,any,any,any>,IextendskeyofE['schema']['indexes']>=EextendsEntity<
infer A,
infer F,
infer C,
infer S>
? Queries<A,F,C,S>[I]extends(arg: infer P)=>any
? P
: never
: never;asyncfunctionlistTasksByProject(key: QueryIndex<typeoftasks,'projects'>){const{ data }=awaittasks.query.projects(key).go();returndata;}asyncfunctionlistTasksByBacklog(key: QueryIndex<typeoftasks,'backlog'>){const{ data }=awaittasks.query.backlog(key).go();returndata;}asyncfunctionlistTasksByAssigned(key: QueryIndex<typeoftasks,'assigned'>){const{ data }=awaittasks.query.assigned(key).go();returndata;}
Furthermore, I noticed the update(...).set(...).go() operation always returns a partial result, even though the actual result can be overridden by providing go({ response: 'all_new' }). I have created the following type that should return a complete result for all_new and all_old, a partial result for updated_new and updated_old, and null for none. The response type default is missing, because I didn't know what the default type is.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I created some additional helper types and I'd like to hear if you're interested in adding them to the library.
ElectroDB Playground
The
GetEntityItem
andDeleteEntityItem
types are additions for the already existing Create and Update types:The
QueryIndex
type extracts the allowed keys of the different query operations:Furthermore, I noticed the
update(...).set(...).go()
operation always returns a partial result, even though the actual result can be overridden by providinggo({ response: 'all_new' })
. I have created the following type that should return a complete result forall_new
andall_old
, a partial result forupdated_new
andupdated_old
, andnull
fornone
. The response typedefault
is missing, because I didn't know what the default type is.If you think it makes sense to add one of these types, I could submit a PR.
Beta Was this translation helpful? Give feedback.
All reactions