diff --git a/adonis-typings/orm.ts b/adonis-typings/orm.ts new file mode 100644 index 00000000..c7a64419 --- /dev/null +++ b/adonis-typings/orm.ts @@ -0,0 +1,60 @@ +// /* +// * @adonisjs/lucid +// * +// * (c) Harminder Virk +// * +// * For the full copyright and license information, please view the LICENSE +// * file that was distributed with this source code. +// */ + +// declare module '@ioc:Adonis/Lucid/Orm' { +// import { +// InsertQueryBuilderContract, +// DatabaseQueryBuilderContract, +// } from '@ioc:Adonis/Lucid/DatabaseQueryBuilder' + +// import { +// ModelConstructorContract as BaseModelConstructorContract, +// ModelContract as BaseModelContract, +// AdapterContract as BaseAdapterContract, +// } from '@poppinss/data-models' + +// export interface OrmQueryBuilder< +// Model extends ModelConstructorContract, +// Result extends any, +// > extends DatabaseQueryBuilderContract, ExcutableQueryBuilderContract { +// } + +// export interface ModelConstructorContract extends BaseModelConstructorContract { +// $connection?: string, +// $increments: boolean, +// $table: string, + +// refs: any, + +// $getSaveQuery ( +// client: QueryClientContract, +// action: 'insert', +// ): InsertQueryBuilderContract, + +// $getSaveQuery ( +// client: QueryClientContract, +// action: 'update', +// ): OrmQueryBuilder, + +// $getSaveQuery ( +// client: QueryClientContract, +// action: 'insert' | 'update', +// ): InsertQueryBuilderContract | OrmQueryBuilder, + +// query (): OrmQueryBuilder this>, +// } + +// export interface ModelContract extends BaseModelContract { +// $getConstructor (): ModelConstructorContract, +// } + +// export interface AdapterContract extends BaseAdapterContract { +// insert (instance: ModelContract, attributes: any): Promise +// } +// } diff --git a/src/Orm/Adapter/index.ts b/src/Orm/Adapter/index.ts new file mode 100644 index 00000000..a977b7fe --- /dev/null +++ b/src/Orm/Adapter/index.ts @@ -0,0 +1,72 @@ +/* + * @adonisjs/lucid + * + * (c) Harminder Virk + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. +*/ + +/// +/// + +// import { DatabaseContract } from '@ioc:Adonis/Lucid/Database' +// import { AdapterContract, ModelContract } from '@ioc:Adonis/Lucid/Orm' + +// /** +// * Adapter to execute queries for a given model. Please note that adapters +// * are stateless and only one instance of adapter is used across the +// * app, so make sure not to store any state. +// */ +// export class Adapter implements AdapterContract { +// constructor (private _db: DatabaseContract) {} + +// public async insert (model: ModelContract, attributes: any): Promise { +// const modelConstructor = model.$getConstructor() + +// /** +// * Pulling the query client for a given connection. +// */ +// const client = this._db.connection(modelConstructor.$connection) + +// * +// * Letting model give us the insert query. This enables the end user +// * to add some constraints to the query builder before returning +// * it back to us + +// const query = modelConstructor.$getSaveQuery(client, 'insert') + +// /** +// * Execute the query +// */ +// const result = await query.insert(attributes) + +// /** +// * Set id when increments is true +// */ +// if (modelConstructor.$increments) { +// model.$consumeAdapterResult({ [modelConstructor.$primaryKey]: result[0] }) +// } +// } + +// public async update (model: ModelContract, dirty: any): Promise { +// const modelConstructor = model.$getConstructor() + +// /** +// * Pulling the query client for a given connection. +// */ +// const client = this._db.connection(modelConstructor.$connection) + +// /** +// * Letting model give us the insert query. This enables the end user +// * to add some constraints to the query builder before returning +// * it back to us +// */ +// const query = modelConstructor.$getSaveQuery(client, 'update') + +// /** +// * Execute the query +// */ +// await query.update(dirty) +// } +// }