Skip to content

Instantly share code, notes, and snippets.

@WimJongeneel
Last active December 30, 2019 14:52
Show Gist options
  • Save WimJongeneel/41cafea1e9840d2fc694189b01077b8d to your computer and use it in GitHub Desktop.
Save WimJongeneel/41cafea1e9840d2fc694189b01077b8d to your computer and use it in GitHub Desktop.
const odata = <T>(name: string, baseuri = '/odata'): IQueryable<T> => {
const exprs: Expr<T>[] = []
return {
where(e) {
exprs.push(e(builder()).getExpr())
return this
},
toArray: async () => {
const res = await fetch(`${baseuri}/${name}?$filter=${exprs.map(compileOdata).join(' and ')}`)
const json = await res.json()
return json.value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment