mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
984 B
36 lines
984 B
3 years ago
|
import ApiFactory from '@/plugins/ncApis/apiFactory'
|
||
|
|
||
|
export default function({ store: $store, $axios, ...rest }, inject) {
|
||
|
let instanceRefs = {}
|
||
|
let projectId = null
|
||
|
|
||
|
inject('ncApis', {
|
||
3 years ago
|
get: ({ table, dbAlias = 'db', env = '_noco', type }) => {
|
||
3 years ago
|
if (!$store.state.meta.metas[table]) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if (instanceRefs[env] && instanceRefs[env][dbAlias] && instanceRefs[env][dbAlias][table]) {
|
||
|
return instanceRefs[env][dbAlias][table]
|
||
|
}
|
||
|
|
||
|
instanceRefs[env] = instanceRefs[env] || {}
|
||
|
instanceRefs[env][dbAlias] = instanceRefs[env][dbAlias] || {}
|
||
|
|
||
|
instanceRefs[env][dbAlias][table] = ApiFactory.create(
|
||
|
table,
|
||
3 years ago
|
type || $store.getters['project/GtrProjectType'],
|
||
3 years ago
|
{ $store, $axios, projectId, dbAlias, env, table }
|
||
|
)
|
||
|
|
||
|
return instanceRefs[env][dbAlias][table]
|
||
|
},
|
||
|
clear: () => {
|
||
|
instanceRefs = {}
|
||
|
},
|
||
|
setProjectId: (_projectId) => {
|
||
|
projectId = _projectId
|
||
|
}
|
||
|
})
|
||
|
}
|