DataSourceManager
Data source manager, used to manage DataSource instances.
1. Instance Properties
collectionTemplateManager
Used to manage CollectionTemplate instances.
import { Plugin, CollectionTemplate } from '@tachybase/client'
class MyCollectionTemplate extends CollectionTemplate {
name = 'my-collection-template'
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.collectionTemplateManager.addCollectionTemplates([
MyCollectionTemplate,
])
}
}
For details please refer to: CollectionTemplateManager
collectionFieldInterfaceManager
Used to manage CollectionFieldInterface instances.
import { Plugin, CollectionFieldInterface } from '@tachybase/client'
class MyCollectionFieldInterface extends CollectionFieldInterface {
name = 'my-collection-field-interface'
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.collectionFieldInterfaceManager.addFieldInterfaces([
MyCollectionFieldInterface,
])
}
}
For details please refer to: CollectionFieldInterfaceManager
2. Instance Methods
addCollectionTemplates()
Shortcut method for CollectionTemplateManager, used to add CollectionTemplate.
class DataSourceManager {
addCollectionTemplates(templates: CollectionTemplate[]): void
}
import { Plugin, CollectionTemplate } from '@tachybase/client'
class MyCollectionTemplate extends CollectionTemplate {
name = 'my-collection-template'
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.collectionTemplateManager.addCollectionTemplates([
MyCollectionTemplate,
])
}
}
For more details please refer to: CollectionTemplateManager
addFieldInterfaces()
Shortcut method for CollectionFieldInterfaceManager, used to add CollectionFieldInterface.
class DataSourceManager {
addFieldInterfaces(fieldInterfaces: CollectionFieldInterface[]): void
}
import { Plugin, CollectionFieldInterface } from '@tachybase/client'
class MyCollectionFieldInterface extends CollectionFieldInterface {
name = 'my-collection-field-interface'
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.collectionFieldInterfaceManager.addFieldInterfaces([
MyCollectionFieldInterface,
])
}
}
For more details please refer to: CollectionFieldInterfaceManager
addCollectionMixins()
Used to add Mixins for Collection.
class DataSourceManager {
addCollectionMixins(mixins: (typeof Collection)[]): void
}
import { Plugin, Collection } from '@tachybase/client'
class MyCollectionMixin extends Collection {
otherMethod() {
console.log('otherMethod')
}
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.addCollectionMixins([MyCollectionMixin])
}
}
const MyComponent = () => {
const collection = useCollection<MyCollectionMixin>()
collection.otherMethod()
}
For more details please refer to: CollectionMixins
addDataSource()
Used to add DataSource.
class DataSourceManager {
addDataSource(DataSource: DataSource, options: DataSourceOptions): void
}
import { Plugin, DataSource, DataSourceOptions } from '@tachybase/client'
class MyDataSource extends DataSource {
async getDataSource() {
return {
status: 'loaded',
collections: [{ name: 'users' }],
}
}
}
class MyPlugin extends Plugin {
async load() {
this.app.dataSourceManager.addDataSource(MyDataSource, {
key: 'my-data-source',
displayName: 'My Data Source',
})
}
}
For more details please refer to: DataSource
removeDataSources()
Remove DataSource.
class DataSourceManager {
removeDataSources(keys: string[]): void
}
const MyComponent = () => {
const dataSourceManager = useDataSourceManager()
dataSourceManager.removeDataSources(['my-data-source'])
}
getDataSources()
Get all DataSource instance list.
class DataSourceManager {
getDataSources(): DataSource[]
}
const MyComponent = () => {
const dataSourceManager = useDataSourceManager()
const dataSources = dataSourceManager.getDataSources()
return (
<div>
{dataSources.map(dataSource => (
<div key={dataSource.key}>{dataSource.displayName}</div>
))}
</div>
)
}
getDataSource(key)
Get DataSource instance.
class DataSourceManager {
getDataSource(key: string): DataSource
}
const MyComponent = () => {
const dataSourceManager = useDataSourceManager()
const dataSource = dataSourceManager.getDataSource('my-data-source')
return <div>{dataSource.displayName}</div>
}
getAllCollections()
Get all Collection instances of all DataSources.
class DataSourceManager {
getAllCollections(options?: {
filterCollection?: (collection: Collection) => boolean
filterDataSource?: (dataSource: DataSource) => boolean
}): (DataSourceOptions & { collections: Collection[] })[]
}
const MyComponent = () => {
const dataSourceManager = useDataSourceManager()
const collections = dataSourceManager.getAllCollections()
return (
<div>
{collections.map(({ key, displayName, collections }) => (
<div key={key}>
<h3>{displayName}</h3>
<ul>
{collections.map(collection => (
<li key={collection.name}>{collection.name}</li>
))}
</ul>
</div>
))}
</div>
)
}
reload()
Reload all DataSource.
class DataSourceManager {
reload(): Promise<void>
}
const MyComponent = () => {
const dataSourceManager = useDataSourceManager()
dataSourceManager.reload()
}