import * as _ from "lodash" ; import * as Metadata from "./metadata" ; import * as Query from "./query" ; import { Conditions } from "./query/expressions/conditions" ; export class Table { public static get metadata ( ) { if ( ! ( this as any ) . __metadata ) { ( this as any ) . __metadata = Metadata . Table . createMetadata ( ) ; } return ( this as any ) . __metadata as Metadata . Table . Metadata ; } public static set metadata ( metadata ) { ( this as any ) . __metadata = metadata ; } public static async createTable ( ) { await Query . TableOperations . createTable ( this . metadata ) ; } public static async dropTable ( ) { await Query . TableOperations . dropTable ( this . metadata ) ; } private attributes : { [ key ] : any ; } = { } ; private __writer : Query . Writer < Table > | null = null ; public getAttribute ( name ) { return this . attributes [ name ] ; } public setAttribute ( name , value ) { this . attributes [ name ] = value ; } public setAttributes ( attributes ) { _ . forEach ( attributes , ( value , name ) => { this . setAttribute ( name , value ) ; } ) ; } private get writer ( ) : Query . Writer < Table > { if ( ! this . __writer ) { this . __writer = new Query . Writer ( this . constructor as ITable < Table > ) ; } return this . __writer ; } public async save < T extends Table > ( this , options ? ) { return await this . writer . put ( this , options ) ; } public async delete < T extends Table > ( this , options ? ) { return await this . writer . delete ( this , options ) ; } public serialize ( ) { return this . attributes ; } } export interface ITable < T extends Table > { metadata : Metadata . Table . Metadata ; new ( ) : T ; }