Skip to content

Commit

Permalink
feat: expose usePostgrest
Browse files Browse the repository at this point in the history
  • Loading branch information
waltherjj committed May 19, 2021
1 parent 9ac9163 commit 5b1bbc9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
14 changes: 14 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ The `vue-postgrest` module exports a plugin, a mixin and several helper function
}
```

### usePostgrest(apiRoot, token)

- **Type:** `Function`

- **Arguments:**
- `{string} apiRoot`
- `{string} token`

- **Returns:** `Schema`

- **Usage:**

Used to create a new schema for the specified baseUri with the specified default auth token. If `apiRoot` is undefined, the apiRoot of the existing Schema is used.

### AuthError

Instances of AuthError are thrown when the server rejects the authentication token.
Expand Down
5 changes: 3 additions & 2 deletions src/Plugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Postgrest from './Postgrest'
import Schema, { setDefaultRoot } from './Schema'
import { setDefaultRoot } from './Schema'
import usePostgrest from './use'

export default {
install (Vue, options = {}) {
Expand All @@ -8,7 +9,7 @@ export default {
Vue.component('postgrest', Postgrest)
Object.defineProperty(Vue.prototype, '$postgrest', {
get () {
return new Schema()
return usePostgrest()
}
})
setDefaultRoot(options.apiRoot)
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import Plugin from '@/Plugin'
import { setDefaultToken } from '@/Schema'
import pg from '@/mixin'
import { AuthError, FetchError, PrimaryKeyError, SchemaNotFoundError } from '@/errors'
import usePostgrest from '@/use'

// Auto-install when vue is found (eg. in browser via <script> tag)
if (typeof globalThis !== 'undefined' && globalThis.Vue) {
globalThis.Vue.use(Plugin)
}

export { pg, AuthError, FetchError, PrimaryKeyError, SchemaNotFoundError, setDefaultToken, Plugin as default }
export { pg, AuthError, FetchError, PrimaryKeyError, SchemaNotFoundError, setDefaultToken, usePostgrest, Plugin as default }
7 changes: 7 additions & 0 deletions src/use.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Schema from '@/Schema'

function usePostgrest (...args) {
return new Schema(...args)
}

export default usePostgrest

0 comments on commit 5b1bbc9

Please sign in to comment.