Skip to content

Commit

Permalink
BasicQuery contract definition #4
Browse files Browse the repository at this point in the history
  • Loading branch information
nhat-phan committed Apr 4, 2018
1 parent a19cc5e commit 333c163
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 9 deletions.
57 changes: 54 additions & 3 deletions dist/lib/query-builders/interfaces/IBasicQuery.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,68 @@
export declare type OrderDirection = 'asc' | 'desc';
export interface IBasicQuery {
/**
* Set the query with given name
* @param {string} name
*/
queryName(name: string): this;
/**
* Get the primary key name
*/
getPrimaryKey(): string;
/**
* Set the query log group name
*
* @param {string} group QueryLog group
*/
setLogGroup(group: string): this;
/**
* Set the columns or fields to be selected.
*
* @param {string|string[]} fields
*/
select(field: string): this;
/**
* Set the columns or fields to be selected.
*
* @param {string|string[]} fields
*/
select(fields: string[]): this;
/**
* Set the columns or fields to be selected.
*
* @param {string|string[]} fields
*/
select(...fields: Array<string | string[]>): this;
distinct(field: string): this;
distinct(field: Array<string>): this;
distinct(...fields: Array<string>): this;
/**
* Add an "order by" clause to the query.
*
* @param {string} field
*/
orderBy(field: string): this;
/**
* Add an "order by" clause to the query.
*
* @param {string} field
* @param {string} direction
*/
orderBy(field: string, direction: OrderDirection): this;
/**
* Add an "order by" clause to the query with direction ASC.
*
* @param {string} field
* @param {string} direction
*/
orderByAsc(field: string): this;
/**
* Add an "order by" clause to the query with direction DESC.
*
* @param {string} field
* @param {string} direction
*/
orderByDesc(field: string): this;
/**
* Set the "limit" value of the query.
* @param {number} records
*/
limit(record: number): this;
}
4 changes: 3 additions & 1 deletion dist/lib/v1.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IFactory } from './factory/interfaces/IFactory';
import { IFactoryBuilder, IFactoryBuilderCollection } from './factory/interfaces/IFactoryBuilder';
import { IFactoryManager } from './factory/interfaces/IFactoryManager';
import { IEloquentDriverProvider } from './providers/interfaces/IEloquentDriverProvider';
import { IBasicQuery } from './query-builders/interfaces/IBasicQuery';
export declare type Faker = ChanceFaker;
export { Collection };
export { Eloquent, Mongoose, EloquentMongoose } from './model/Eloquent';
Expand All @@ -30,7 +31,6 @@ export { FactoryFacade, Factory, factory } from './facades/global/FactoryFacade'
export { MongooseProviderFacade, MongooseProvider } from './facades/global/MongooseProviderFacade';
export { QueryLogFacade, QueryLog } from './facades/global/QueryLogFacade';
export { IMongooseProvider } from './providers/interfaces/IMongooseProvider';
export { IBasicQuery } from './query-builders/interfaces/IBasicQuery';
export { IConditionQuery } from './query-builders/interfaces/IConditionQuery';
export { IFetchResultQuery } from './query-builders/interfaces/IFetchResultQuery';
export { IQueryConvention } from './query-builders/interfaces/IQueryConvention';
Expand Down Expand Up @@ -60,6 +60,8 @@ export declare namespace NajsEloquent {
}
}
namespace QueryBuilder {
interface BasicQuery extends IBasicQuery {
}
}
namespace Provider {
interface EloquentDriverProvider extends IEloquentDriverProvider {
Expand Down
62 changes: 59 additions & 3 deletions lib/query-builders/interfaces/IBasicQuery.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,80 @@
export type OrderDirection = 'asc' | 'desc'

export interface IBasicQuery {
/**
* Set the query with given name
* @param {string} name
*/
queryName(name: string): this

/**
* Get the primary key name
*/
getPrimaryKey(): string

/**
* Set the query log group name
*
* @param {string} group QueryLog group
*/
setLogGroup(group: string): this

/**
* Set the columns or fields to be selected.
*
* @param {string|string[]} fields
*/
select(field: string): this
/**
* Set the columns or fields to be selected.
*
* @param {string|string[]} fields
*/
select(fields: string[]): this
/**
* Set the columns or fields to be selected.
*
* @param {string|string[]} fields
*/
select(...fields: Array<string | string[]>): this

distinct(field: string): this
distinct(field: Array<string>): this
distinct(...fields: Array<string>): this
// distinct(field: string): this
// distinct(field: Array<string>): this
// distinct(...fields: Array<string>): this

/**
* Add an "order by" clause to the query.
*
* @param {string} field
*/
orderBy(field: string): this
/**
* Add an "order by" clause to the query.
*
* @param {string} field
* @param {string} direction
*/
orderBy(field: string, direction: OrderDirection): this

/**
* Add an "order by" clause to the query with direction ASC.
*
* @param {string} field
* @param {string} direction
*/
orderByAsc(field: string): this

/**
* Add an "order by" clause to the query with direction DESC.
*
* @param {string} field
* @param {string} direction
*/
orderByDesc(field: string): this

/**
* Set the "limit" value of the query.
* @param {number} records
*/
limit(record: number): this
}
4 changes: 2 additions & 2 deletions lib/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IFactory } from './factory/interfaces/IFactory'
import { IFactoryBuilder, IFactoryBuilderCollection } from './factory/interfaces/IFactoryBuilder'
import { IFactoryManager } from './factory/interfaces/IFactoryManager'
import { IEloquentDriverProvider } from './providers/interfaces/IEloquentDriverProvider'
import { IBasicQuery } from './query-builders/interfaces/IBasicQuery'

// Public classes ------------------------------------------------------------------------------------------------------
export type Faker = ChanceFaker
Expand All @@ -39,7 +40,6 @@ export { QueryLogFacade, QueryLog } from './facades/global/QueryLogFacade'

export { IMongooseProvider } from './providers/interfaces/IMongooseProvider'

export { IBasicQuery } from './query-builders/interfaces/IBasicQuery'
export { IConditionQuery } from './query-builders/interfaces/IConditionQuery'
export { IFetchResultQuery } from './query-builders/interfaces/IFetchResultQuery'
export { IQueryConvention } from './query-builders/interfaces/IQueryConvention'
Expand Down Expand Up @@ -76,7 +76,7 @@ export namespace NajsEloquent {
}

export namespace QueryBuilder {

export interface BasicQuery extends IBasicQuery {}
}

export namespace Provider {
Expand Down

0 comments on commit 333c163

Please sign in to comment.