import { IApp , IAppsStorage , IConfiguration } from "@staticdeploy/core" ; import { Knex } from "knex" ; import convertErrors from "./common/convertErrors" ; import tables from "./common/tables" ; @ convertErrors export default class AppsStorage implements IAppsStorage { constructor ( private knex ) { } async findOne ( id ) { const [ app = null ] = await this . knex ( tables . apps ) . where ( { id } ) ; return app ; } async findOneByName ( name ) { const [ app = null ] = await this . knex ( tables . apps ) . where ( { name } ) ; return app ; } async findMany ( ) { const apps = await this . knex ( tables . apps ) ; return apps ; } async oneExistsWithId ( id ) { const [ app = null ] = await this . knex ( tables . apps ) . select ( "id" ) . where ( { id } ) ; return app !== null ; } async oneExistsWithName ( name ) { const [ app = null ] = await this . knex ( tables . apps ) . select ( "id" ) . where ( { name } ) ; return app !== null ; } async createOne ( toBeCreatedApp ) { const [ createdApp ] = await this . knex ( tables . apps ) . insert ( toBeCreatedApp ) . returning ( "*" ) ; return createdApp ; } async updateOne ( id , patch ) { const [ updatedApp ] = await this . knex ( tables . apps ) . where ( { id } ) . update ( patch ) . returning ( "*" ) ; return updatedApp ; } async deleteOne ( id ) { await this . knex ( tables . apps ) . where ( { id } ) . delete ( ) ; } }