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.
35 lines
970 B
35 lines
970 B
import ApiFactory from '@/plugins/ncApis/apiFactory' |
|
|
|
export default function({ store: $store, $axios, ...rest }, inject) { |
|
let instanceRefs = {} |
|
let projectId = null |
|
|
|
inject('ncApis', { |
|
get: ({ table, dbAlias = 'db', env = '_noco' }) => { |
|
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, |
|
$store.getters['project/GtrProjectType'], |
|
{ $store, $axios, projectId, dbAlias, env, table } |
|
) |
|
|
|
return instanceRefs[env][dbAlias][table] |
|
}, |
|
clear: () => { |
|
instanceRefs = {} |
|
}, |
|
setProjectId: (_projectId) => { |
|
projectId = _projectId |
|
} |
|
}) |
|
}
|
|
|