Skip to content

Commit

Permalink
fix(types): adjust return type of some types
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Sep 1, 2022
1 parent a9b0b9f commit e6a2340
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 53 deletions.
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
version: "3"

services:
mongo:
container_name: athenna_mongo
image: mongo
ports:
- "27018:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 12345

mysql:
container_name: athenna_mysql
image: mysql
ports:
- "3307:3306"
environment:
MYSQL_DATABASE: athenna
MYSQL_USER: root
MYSQL_PASSWORD: 12345
MYSQL_ROOT_PASSWORD: 12345
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'

Expand Down
117 changes: 89 additions & 28 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,15 +848,15 @@ export class Criteria {
* @param tableName {string|any}
* @return {Criteria}
*/
static table(tableName: string | any): Criteria
static table(tableName: string | any): typeof Criteria

/**
* Set the columns that should be selected on query.
*
* @param columns {string}
* @return {Criteria}
*/
static select(...columns: string[]): Criteria
static select(...columns: string[]): typeof Criteria

/**
* Set a include statement in your query.
Expand All @@ -865,7 +865,7 @@ export class Criteria {
* @param [operation] {string}
* @return {Criteria}
*/
static includes(relation: string | any, operation?: string): Criteria
static includes(relation: string | any, operation?: string): typeof Criteria

/**
* Set a where statement in your query.
Expand All @@ -874,7 +874,7 @@ export class Criteria {
* @param [value] {any}
* @return {Criteria}
*/
static where(statement: string | Record<string, any>, value?: any): Criteria
static where(statement: string | Record<string, any>, value?: any): typeof Criteria

/**
* Set a where like statement in your query.
Expand All @@ -883,7 +883,7 @@ export class Criteria {
* @param [value] {any}
* @return {Criteria}
*/
static whereLike(statement: string | Record<string, any>, value?: any): Criteria
static whereLike(statement: string | Record<string, any>, value?: any): typeof Criteria

/**
* Set a where ILike statement in your query.
Expand All @@ -892,7 +892,7 @@ export class Criteria {
* @param [value] {any}
* @return {Criteria}
*/
static whereILike(statement: string | Record<string, any>, value?: any): Criteria
static whereILike(statement: string | Record<string, any>, value?: any): typeof Criteria

/**
* Set a where not statement in your query.
Expand All @@ -901,7 +901,7 @@ export class Criteria {
* @param [value] {any}
* @return {Criteria}
*/
static whereNot(statement: string | Record<string, any>, value?: any): Criteria
static whereNot(statement: string | Record<string, any>, value?: any): typeof Criteria

/**
* Set a where in statement in your query.
Expand All @@ -910,7 +910,7 @@ export class Criteria {
* @param values {any[]}
* @return {Criteria}
*/
static whereIn(columnName: string, values?: any[]): Criteria
static whereIn(columnName: string, values?: any[]): typeof Criteria

/**
* Set a where not in statement in your query.
Expand All @@ -919,23 +919,23 @@ export class Criteria {
* @param values {any[]}
* @return {Criteria}
*/
static whereNotIn(columnName: string, values?: any[]): Criteria
static whereNotIn(columnName: string, values?: any[]): typeof Criteria

/**
* Set a where null statement in your query.
*
* @param columnName {string}
* @return {Criteria}
*/
static whereNull(columnName: string): Criteria
static whereNull(columnName: string): typeof Criteria

/**
* Set a where not null statement in your query.
*
* @param columnName {string}
* @return {Criteria}
*/
static whereNotNull(columnName: string): Criteria
static whereNotNull(columnName: string): typeof Criteria

/**
* Set a where between statement in your query.
Expand All @@ -944,7 +944,7 @@ export class Criteria {
* @param values {[any, any]}
* @return {Criteria}
*/
static whereBetween(columnName: string, values: [any, any]): Criteria
static whereBetween(columnName: string, values: [any, any]): typeof Criteria

/**
* Set a where not between statement in your query.
Expand All @@ -953,7 +953,7 @@ export class Criteria {
* @param values {[any, any]}
* @return {Criteria}
*/
static whereNotBetween(columnName: string, values: [any, any]): Criteria
static whereNotBetween(columnName: string, values: [any, any]): typeof Criteria

/**
* Set a order by statement in your query.
Expand All @@ -962,23 +962,23 @@ export class Criteria {
* @param [direction] {'asc'|'desc'|'ASC'|'DESC'}
* @return {Criteria}
*/
static orderBy(columnName: string, direction?: 'asc' | 'desc' | 'ASC' | 'DESC'): Criteria
static orderBy(columnName: string, direction?: 'asc' | 'desc' | 'ASC' | 'DESC'): typeof Criteria

/**
* Set the skip number in your query.
*
* @param number {number}
* @return {Criteria}
*/
static skip(number: number): Criteria
static skip(number: number): typeof Criteria

/**
* Set the limit number in your query.
*
* @param number {number}
* @return {Criteria}
*/
static limit(number: number): Criteria
static limit(number: number): typeof Criteria

/**
* Get the criteria map.
Expand Down Expand Up @@ -1533,47 +1533,47 @@ export class Column {
*
* @return {Column}
*/
static type(type): Column
static type(type): typeof Column

/**
* Set the default value of your column.
*
* @return {Column}
*/
static default(value): Column
static default(value): typeof Column

/**
* Set if this column should be hidded.
*/
static isHidden(): Column
static isHidden(): typeof Column

/**
* Set if your column is auto generated.
*
* @return {Column}
*/
static isGenerated(): Column
static isGenerated(): typeof Column

/**
* Set if your column is primary.
*
* @return {Column}
*/
static isPrimary(): Column
static isPrimary(): typeof Column

/**
* Set if your column is unique.
*
* @return {Column}
*/
static isUnique(): Column
static isUnique(): typeof Column

/**
* Set if your column is nullable.
*
* @return {Column}
*/
static isNullable(): Column
static isNullable(): typeof Column

/**
* Get the clean object built.
Expand Down Expand Up @@ -1642,38 +1642,38 @@ export class Relation {
* @param model {any}
* @return {Relation}
*/
static target(model: any): Relation
static target(model: any): typeof Relation

/**
* Set the relation type.
*
* @param type {"one-to-one","one-to-many","many-to-one","many-to-many"}
* @return {Relation}
*/
static type(type: "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many"): Relation
static type(type: "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many"): typeof Relation

/**
* Set the inverse side of your model schema.
*
* @param name
* @return {Relation}
*/
static inverseSide(name: string): Relation
static inverseSide(name: string): typeof Relation

/**
* Set the column that the relation should join.
*
* @param column
* @return {Relation}
*/
static joinColumn(column: any): Relation
static joinColumn(column: any): typeof Relation

/**
* Set if relation should be cascaded on delete/update.
*
* @return {Relation}
*/
static cascade(): Relation
static cascade(): typeof Relation

/**
* Get the clean object built.
Expand All @@ -1682,3 +1682,64 @@ export class Relation {
*/
static get(): any
}

export class DriverFactory {
/**
* Return all available drivers.
*
* @param {boolean} onlyConnected
* @return {string[]}
*/
static availableDrivers(onlyConnected?: boolean): string[]

/**
* Fabricate a new connection with some database driver.
*
* @param {string} connectionName
* @return {{ Driver: any, clientConnection?: any }}
*/
static fabricate(connectionName: string): { Driver: any, clientConnection?: any }

/**
* Create a new driver implementation.
*
* @param {string} name
* @param {any} driver
*/
static createDriver(name: string, driver: any): void

/**
* Create the connection with database by driver name.
*
* @param {string} driverName
* @param {string} [conName]
* @param {boolean} [saveOnDriver]
* @return {Promise<any>}
*/
static createConnectionByDriver(driverName: string, conName?: string, saveOnDriver?: boolean): Promise<any>

/**
* Close the connection with database by driver name.
*
* @param {string} driverName
* @return {Promise<void>}
*/
static closeConnectionByDriver(driverName: string): Promise<void>

/**
* Create the connection with database by connection name.
*
* @param {string} [conName]
* @param {boolean} [saveOnDriver]
* @return {Promise<any>}
*/
static createConnectionByName(conName?: string, saveOnDriver?: boolean): Promise<any>

/**
* Close the connection with database by connection name.
*
* @param {string} [conName]
* @return {Promise<void>}
*/
static closeConnectionByName(conName?: string): Promise<void>
}
22 changes: 11 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

import { DriverFactory } from '#src/Factories/DriverFactory'

export * from './Facades/Database.js'

export * from './Factories/ModelFactory.js'
export * from './Factories/DriverFactory.js'
export * from './Factories/ConnectionFactory.js'

export * from './Models/Model.js'
export * from './Models/Column.js'
export * from './Models/Relation.js'
export * from './Models/Criteria.js'

export class DatabaseImpl {
/**
* The connection name used for this instance.
Expand Down Expand Up @@ -1185,14 +1196,3 @@ export class Transaction {
return this
}
}

export * from './Facades/Database.js'

export * from './Factories/ModelFactory.js'
export * from './Factories/DriverFactory.js'
export * from './Factories/ConnectionFactory.js'

export * from './Models/Model.js'
export * from './Models/Column.js'
export * from './Models/Relation.js'
export * from './Models/Criteria.js'
22 changes: 10 additions & 12 deletions tests/Stubs/configs/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,17 @@ export default {

mongo: {
driver: 'mongo',
protocol: 'mongodb',
host: '127.0.0.1',
port: 27017,
database: 'mongodb',
username: 'mongo',
host: 'localhost',
port: 27018,
database: 'admin',
username: 'root',
password: '12345',
options: {
w: 'majority',
replicaSet: 'rs',
retryWrites: true,
useNewUrlParser: true,
useUnifiedTopology: true,
},
logging: ['error', 'warn'],
synchronize: false,
writeConcern: 'majority',
retryWrites: true,
useNewUrlParser: true,
useUnifiedTopology: true,
},
},

Expand Down

0 comments on commit e6a2340

Please sign in to comment.