CollectionManager

Used to manage Collection, which is managed by DataSource.

Instance Methods

addCollections(collections)

Add data tables.

  • Type
class CollectionManager {
  addCollections(collections: CollectionOptions[]): void
}
  • Example
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.

  • Type
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.

  • Type
class CollectionManager {
  reAddCollections(collectionInstances: Collection[]): void
}
  • Example
const userCollectionInstance = collectionManager.getCollection('users');
collectionManager.reAddCollections([userCollectionInstance]);

getCollections(predicate?)

Get data table array.

  • Type
class CollectionManager {
  getCollections(predicate?: (collection: Collection) => boolean)
}
  • Example
collectionManager.getCollections(); // [ userCollection ]

collectionManager.getCollections(collection => collection.name === 'posts'); // [ postCollection ]

getCollection(path)

Get data table.

  • Type
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.

  • Type
class CollectionManager {
  getCollectionFields(collectionName: string): CollectionFieldOptions[];
}
  • Example
collectionManager.getCollectionFields('users'); // [ { name: 'username', type: 'string', title: 'Username', .. }, { name: 'password', type: 'password', title: 'Password', .. } ]

getCollectionName(path)

Get data table name.

  • Type
class CollectionManager {
  getCollectionName(path: string: GetCollectionOptions): string | undefined;
}
  • Example
collectionManager.getCollectionName('users'); // 'users'

collectionManager.getCollectionName('users.profiles'); // 'profiles'

getCollectionField(path)

Get data table field.

  • Type
class CollectionManager {
  getCollectionField(path: string: GetCollectionOptions): CollectionFieldOptions | undefined;
}
  • Example
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
Total visits  times     Total visitors  times     Total reading  times.   Powered by Tego Team