@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.81 kB
JavaScript
import e from"./parents/static-repository.mjs";import t from"zod";var n=class extends e{constructor(e,t){super(e,t,`lucid_collection_migrations`)}tableSchema=t.object({id:t.number(),collection_key:t.string(),migration_plans:t.unknown(),collection_schema:t.unknown(),created_at:t.union([t.string(),t.date()]).nullable(),table_name_map:t.record(t.string(),t.string())});columnFormats={id:this.dbAdapter.getDataType(`primary`),collection_key:this.dbAdapter.getDataType(`text`),table_name_map:this.dbAdapter.getDataType(`text`),migration_plans:this.dbAdapter.getDataType(`json`),collection_schema:this.dbAdapter.getDataType(`json`),created_at:this.dbAdapter.getDataType(`timestamp`)};queryConfig=void 0;async selectLatestByCollectionKey(e){let t=this.db.selectFrom(this.tableName).selectAll().where(`collection_key`,`=`,e.collectionKey).orderBy(`id`,`desc`).limit(1),n=await this.executeQuery(()=>t.executeTakeFirst(),{method:`selectLatestByCollectionKey`});return n.response.error?n.response:this.validateResponse(n,{...e.validation,mode:`single`,selectAll:!0})}async selectLatestByCollectionKeysMap(e){if(e.collectionKeys.length===0)return{error:void 0,data:[]};let t=this.db.selectFrom(`lucid_collection_migrations as cm`).innerJoin(this.db.selectFrom(this.tableName).select([`collection_key`,e=>e.fn.max(`id`).as(`latest_id`)]).where(`collection_key`,`in`,e.collectionKeys).groupBy(`collection_key`).as(`latest_ids`),e=>e.onRef(`cm.collection_key`,`=`,`latest_ids.collection_key`).onRef(`cm.id`,`=`,`latest_ids.latest_id`)).selectAll(`cm`),n=await this.executeQuery(()=>t.execute(),{method:`selectLatestByCollectionKeysMap`});return n.response.error?n.response:this.validateResponse(n,{...e.validation,mode:`multiple`,selectAll:!0})}};export{n as default};
//# sourceMappingURL=collection-migrations.mjs.map