CollectionManager
Used to manage Collection, which is managed by DataSource.
Instance Methods
addCollections(collections)
Add data tables.
class CollectionManager {
addCollections(collections: CollectionOptions[]): void
}
const userCollectionOptions = {
"name": "users",
"title": "Users",
fields: [
// ...
],
};
collectionManager.addCollections([userCollectionOptions]);
setCollections(collections)
Reset data tables, will first remove all data tables, then call addCollections() to add data tables.
class CollectionManager {
setCollections(collections: CollectionOptions[]): void
}
reAddCollections(collections)
Since adding CollectionTemplate or CollectionMixins will affect Collection instantiation, a method to re-add data tables is provided.
class CollectionManager {
reAddCollections(collectionInstances: Collection[]): void
}
const userCollectionInstance = collectionManager.getCollection('users');
collectionManager.reAddCollections([userCollectionInstance]);
getCollections(predicate?)
Get data table array.
class CollectionManager {
getCollections(predicate?: (collection: Collection) => boolean)
}
collectionManager.getCollections(); // [ userCollection ]
collectionManager.getCollections(collection => collection.name === 'posts'); // [ postCollection ]
getCollection(path)
Get data table.
class CollectionManager {
getCollection<Mixins = {}>(path: string): (Mixins & Collection) | undefined
}
-
Detailed Explanation
path parameter can be data table name or relationship field path.
path: 'users': Get users data table
path: 'users.posts': Get the data table corresponding to the posts association field of the users data table, i.e., postCollection
-
Example
collectionManager.getCollection('users'); // userCollection
collectionManager.getCollection('users.posts'); // postCollection
collectionManager.getCollection('users.profileId'); // profileCollection
Use with Mixin:
const collection = collectionManager.getCollection<TestMixin>('users');
const collection = collectionManager.getCollection<TestMixin & TestMixin2>('users');
getCollectionFields(collectionName)
Get data table field list.
class CollectionManager {
getCollectionFields(collectionName: string): CollectionFieldOptions[];
}
collectionManager.getCollectionFields('users'); // [ { name: 'username', type: 'string', title: 'Username', .. }, { name: 'password', type: 'password', title: 'Password', .. } ]
getCollectionName(path)
Get data table name.
class CollectionManager {
getCollectionName(path: string: GetCollectionOptions): string | undefined;
}
collectionManager.getCollectionName('users'); // 'users'
collectionManager.getCollectionName('users.profiles'); // 'profiles'
getCollectionField(path)
Get data table field.
class CollectionManager {
getCollectionField(path: string: GetCollectionOptions): CollectionFieldOptions | undefined;
}
collectionManager.getCollectionField('users.username'); // { name: 'username', type: 'string', title: 'Username', .. }
collectionManager.getCollectionField('users.roles.name'); // Get the name field in the roles table corresponding to the roles association field