-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: start refactor to engines (#81)
* chore: start refactor to engines * chore: add newline
- Loading branch information
1 parent
be5f147
commit f76a497
Showing
13 changed files
with
385 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'iql': minor | ||
--- | ||
|
||
chore: start refactor to engines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { QueryCompiler } from './interfaces'; | ||
|
||
/** | ||
* const findB = extend(findA, { | ||
* to: { | ||
* public: (raw) => ({ ...raw, happy: true }), | ||
* }, | ||
* from: { | ||
* register: (id: string) => ({ id }), | ||
* }, | ||
* }); | ||
* | ||
* const params = findB.fromRegister('iql'); // row is of type IUserParams | ||
* const { rows } = await pg.query<QueryResylt<typeof findB>>(findB.compile(params)); | ||
* const publicUser = findB.toPublic(rows[0]); // publicUser.happy === true | ||
*/ | ||
export const extend = < | ||
T extends Record<string, unknown[]>, | ||
U extends Record<string, unknown>, | ||
K, | ||
L, | ||
M extends Record<string, unknown[]>, | ||
N extends Record<string, unknown>, | ||
>( | ||
input: QueryCompiler<K, L, M, N>, | ||
change: { | ||
from?: { [R in keyof T]: (...args: T[R]) => L }; | ||
to?: { [R in keyof U]: (raw: K) => U[R] }; | ||
}, | ||
): QueryCompiler<K, L, M & T, N & U> => | ||
({ | ||
...input, | ||
...(change.from | ||
? Object.entries(change.from).reduce( | ||
(acc, [from, value]) => ({ | ||
...acc, | ||
[`from${from[0].toUpperCase()}${from.slice(1)}`]: value as (...args: T[keyof T]) => L, | ||
}), | ||
{}, | ||
) | ||
: {}), | ||
...(change.to | ||
? Object.entries(change.to).reduce( | ||
(acc, [from, value]) => ({ | ||
...acc, | ||
[`to${from[0].toUpperCase()}${from.slice(1)}`]: value as (raw: K) => U[keyof U], | ||
}), | ||
{}, | ||
) | ||
: {}), | ||
} as QueryCompiler<K, L, M & T, N & U>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
export type { | ||
IParamAggregator, | ||
IPostgresInterval, | ||
QueryCompiler, | ||
QueryParameters, | ||
QueryResult, | ||
ValueType, | ||
} from './interfaces'; | ||
export { extend, query } from './query'; | ||
export { intervalStringValue, intervalToMilliseconds } from './interval'; | ||
export { extend } from './extend'; | ||
export type { IParamAggregator, QueryCompiler, QueryParameters, QueryResult, ValueType } from './interfaces'; | ||
export { intervalStringValue, intervalToMilliseconds, query as pg, query } from './pg'; | ||
export type { IPostgresInterval } from './pg'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type { IPostgresInterval } from './interfaces'; | ||
export { intervalStringValue, intervalToMilliseconds } from './interval'; | ||
export { query } from './query'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Postgres internal representation of intervals | ||
*/ | ||
export interface IPostgresInterval { | ||
days?: number; | ||
hours?: number; | ||
minutes?: number; | ||
seconds?: number; | ||
milliseconds?: number; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.