/** * @packageDocumentation * Models are used to interact with APIs and represent data. * * Each Model represents a resource, such as a Property, Branch or Article. * * To generate a new Model from the command line use the command: * * ```bash * yarn generate * ``` * and select the `model` option. Once you provide a name for your model a script will generate the boilerplate files and code for your model including the main Model class file, a `.types.ts` file, a test file, a serializer, as well as an accompanying `dbapi` client helper. * * Most models share these async static methods: * * - `findById()` * - `findOne()` * - `findAll()` * * These methods will return a Promise which resolves to return an object containing either `result`: an instance of the class (in the case of findOne and findById), or `results`: an array of instances (in the case of findAll). For example: * *```ts * // `result` will be an instance of the Property model * const { result: property } = await Property.findById(12345); * * // articles will be an array of instances of the Article model * const { results: articles } = await Article.findAll({ topic: 'news' }); * ``` * * Each model has various instance getters (accessors) to interact with the model instance. Typically these render data, e.g. * * ```ts * // renders the property ID: 12345 * property.id * ``` * * Although getters run like normal methods they do not need to be invoked using (). * * In case you need to access any data which does not have a getter, you can access the data directly using the get() instance method available on every model: * * ```ts * property.get('display_address'); * ``` * * When fetching multiple resources, it’s often beneficial for performance to resolve the promises concurrently using Promise.all(): * * ```ts * // omitting 'await' here so the promise is returned * const heroChunkPromise = ContentChunk.find({ name: 'home_hero' }); * const sidebarChunkPromise = ContentChunk.find({ name: 'home_sidebar' }); * * const [heroChunk, sidebarChunk] = await Promise.all([heroChunkPromise, sidebarChunkPromise]); * ``` * * ## Serializers * * There is a directory `serializers/` (see [Serializers](./API_Reference_Serializers.html)) containing functions to specify the way models should be serialized to JSON. * Because models are complex objects they cannot be passed to client-side code in the same form as they exist on the server, * so they must be converted to serializable versions of those objects. The simplest way to do this is to combine JSON.parse() and JSON.stringify(). * * ```tsx * // in async server component * const { result: property } = await Property.findById(1234); * * const serializableProperty = JSON.parse(JSON.stringify(property)); * * return ( * // 'property' inside the client component will be the object returned by the property serializer * * ) * ``` * * Consider performance when adding new values to a serializer as each method or accessor will be called when constructing the JSON. * * @module API Reference/Models */ export { default as AgencyEmployee } from './api/models/agency-employee'; export * from './api/models/agency'; export { default as Agency } from './api/models/agency'; export * from './api/models/article'; export { default as Article } from './api/models/article'; export * from './api/models/branch'; export { default as Branch } from './api/models/branch'; export * from './api/models/calendar-event'; export { default as CalendarEvent } from './api/models/calendar-event'; export * from './api/models/connection'; export { default as Connection } from './api/models/connection'; export * from './api/models/content-chunk'; export { default as ContentChunk } from './api/models/content-chunk'; export * from './api/models/county'; export { default as County } from './api/models/county'; export * from './api/models/location'; export { default as Location } from './api/models/location'; export * from './api/models/page'; export { default as Page } from './api/models/page'; export * from './api/models/place'; export { default as Place } from './api/models/place'; export * from './api/models/postcode'; export { default as Postcode } from './api/models/postcode'; export * from './api/models/property'; export { default as Property } from './api/models/property'; export * from './api/models/user'; export { default as User } from './api/models/user'; export * from './api/models/admin-user'; export { default as AdminUser } from './api/models/admin-user'; export * from './api/models/image'; export { default as Image } from './api/models/image'; export * from './api/models/lead'; export { default as Lead } from './api/models/lead'; export * from './api/models/testimonial'; export { default as Testimonial } from './api/models/testimonial'; export * from './api/models/stamp-duty-rate'; export { default as StampDutyRate } from './api/models/stamp-duty-rate'; export * from './api/models/model'; //# sourceMappingURL=models.d.ts.map