forked from drizzle-team/drizzle-orm
-
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.
- Loading branch information
1 parent
3f844c4
commit feffcfd
Showing
4 changed files
with
300 additions
and
0 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
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
136 changes: 136 additions & 0 deletions
136
drizzle-orm/src/singlestore-core/query-builders/createMilestone.ts
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,136 @@ | ||
import { entityKind } from '~/entity.ts'; | ||
import { QueryPromise } from '~/query-promise.ts'; | ||
import type { SingleStoreDialect } from '~/singlestore-core/dialect.ts'; | ||
import type { | ||
AnySingleStoreQueryResultHKT, | ||
PreparedQueryHKTBase, | ||
PreparedQueryKind, | ||
SingleStorePreparedQueryConfig, | ||
SingleStoreQueryResultHKT, | ||
SingleStoreQueryResultKind, | ||
SingleStoreSession, | ||
} from '~/singlestore-core/session.ts'; | ||
import type { Query, SQL, SQLWrapper } from '~/sql/sql.ts'; | ||
|
||
export type SingleStoreCreateMilestoneWithout< | ||
T extends AnySingleStoreCreateMilestoneBase, | ||
TDynamic extends boolean, | ||
K extends keyof T & string, | ||
> = TDynamic extends true ? T | ||
: Omit< | ||
SingleStoreCreateMilestoneBase< | ||
T['_']['milestone'], | ||
T['_']['queryResult'], | ||
T['_']['preparedQueryHKT'], | ||
TDynamic, | ||
T['_']['excludedMethods'] | K | ||
>, | ||
T['_']['excludedMethods'] | K | ||
>; | ||
|
||
export type SingleStoreCreateMilestone< | ||
TDatabase extends string = string, | ||
TQueryResult extends SingleStoreQueryResultHKT = AnySingleStoreQueryResultHKT, | ||
TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, | ||
> = SingleStoreCreateMilestoneBase<TDatabase, TQueryResult, TPreparedQueryHKT, true, never>; | ||
|
||
export interface SingleStoreCreateMilestoneConfig { | ||
milestone: string; | ||
database?: string | undefined; | ||
} | ||
|
||
export type SingleStoreCreateMilestonePrepare<T extends AnySingleStoreCreateMilestoneBase> = PreparedQueryKind< | ||
T['_']['preparedQueryHKT'], | ||
SingleStorePreparedQueryConfig & { | ||
execute: SingleStoreQueryResultKind<T['_']['queryResult'], never>; | ||
iterator: never; | ||
}, | ||
true | ||
>; | ||
|
||
type SingleStoreCreateMilestoneDynamic<T extends AnySingleStoreCreateMilestoneBase> = SingleStoreCreateMilestone< | ||
T['_']['milestone'], | ||
T['_']['queryResult'], | ||
T['_']['preparedQueryHKT'] | ||
>; | ||
|
||
type AnySingleStoreCreateMilestoneBase = SingleStoreCreateMilestoneBase<any, any, any, any, any>; | ||
|
||
export interface SingleStoreCreateMilestoneBase< | ||
TMilestone extends string, | ||
TQueryResult extends SingleStoreQueryResultHKT, | ||
TPreparedQueryHKT extends PreparedQueryHKTBase, | ||
TDynamic extends boolean = false, | ||
TExcludedMethods extends string = never, | ||
> extends QueryPromise<SingleStoreQueryResultKind<TQueryResult, never>> { | ||
readonly _: { | ||
readonly milestone: TMilestone; | ||
readonly queryResult: TQueryResult; | ||
readonly preparedQueryHKT: TPreparedQueryHKT; | ||
readonly dynamic: TDynamic; | ||
readonly excludedMethods: TExcludedMethods; | ||
}; | ||
} | ||
|
||
export class SingleStoreCreateMilestoneBase< | ||
TMilestone extends string, | ||
TQueryResult extends SingleStoreQueryResultHKT, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
TPreparedQueryHKT extends PreparedQueryHKTBase, | ||
TDynamic extends boolean = false, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
TExcludedMethods extends string = never, | ||
> extends QueryPromise<SingleStoreQueryResultKind<TQueryResult, never>> implements SQLWrapper { | ||
static readonly [entityKind]: string = 'SingleStoreCreateMilestone'; | ||
|
||
private config: SingleStoreCreateMilestoneConfig; | ||
|
||
constructor( | ||
private milestone: TMilestone, | ||
private session: SingleStoreSession, | ||
private dialect: SingleStoreDialect, | ||
) { | ||
super(); | ||
this.config = { milestone }; | ||
} | ||
|
||
// TODO(singlestore): docs | ||
for(database: string): SingleStoreCreateMilestoneWithout<this, TDynamic, 'for'> { | ||
this.config.database = database; | ||
return this as any; | ||
} | ||
|
||
/** @internal */ | ||
getSQL(): SQL { | ||
return this.dialect.buildCreateMilestoneQuery(this.config); | ||
} | ||
|
||
toSQL(): Query { | ||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL()); | ||
return rest; | ||
} | ||
|
||
prepare(): SingleStoreCreateMilestonePrepare<this> { | ||
return this.session.prepareQuery( | ||
this.dialect.sqlToQuery(this.getSQL()), | ||
undefined, | ||
) as SingleStoreCreateMilestonePrepare<this>; | ||
} | ||
|
||
override execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => { | ||
return this.prepare().execute(placeholderValues); | ||
}; | ||
|
||
private createIterator = (): ReturnType<this['prepare']>['iterator'] => { | ||
const self = this; | ||
return async function*(placeholderValues) { | ||
yield* self.prepare().iterator(placeholderValues); | ||
}; | ||
}; | ||
|
||
iterator = this.createIterator(); | ||
|
||
$dynamic(): SingleStoreCreateMilestoneDynamic<this> { | ||
return this as any; | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
drizzle-orm/src/singlestore-core/query-builders/dropMilestone.ts
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,136 @@ | ||
import { entityKind } from '~/entity.ts'; | ||
import { QueryPromise } from '~/query-promise.ts'; | ||
import type { SingleStoreDialect } from '~/singlestore-core/dialect.ts'; | ||
import type { | ||
AnySingleStoreQueryResultHKT, | ||
PreparedQueryHKTBase, | ||
PreparedQueryKind, | ||
SingleStorePreparedQueryConfig, | ||
SingleStoreQueryResultHKT, | ||
SingleStoreQueryResultKind, | ||
SingleStoreSession, | ||
} from '~/singlestore-core/session.ts'; | ||
import type { Query, SQL, SQLWrapper } from '~/sql/sql.ts'; | ||
|
||
export type SingleStoreDropMilestoneWithout< | ||
T extends AnySingleStoreDropMilestoneBase, | ||
TDynamic extends boolean, | ||
K extends keyof T & string, | ||
> = TDynamic extends true ? T | ||
: Omit< | ||
SingleStoreDropMilestoneBase< | ||
T['_']['milestone'], | ||
T['_']['queryResult'], | ||
T['_']['preparedQueryHKT'], | ||
TDynamic, | ||
T['_']['excludedMethods'] | K | ||
>, | ||
T['_']['excludedMethods'] | K | ||
>; | ||
|
||
export type SingleStoreDropMilestone< | ||
TDatabase extends string = string, | ||
TQueryResult extends SingleStoreQueryResultHKT = AnySingleStoreQueryResultHKT, | ||
TPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase, | ||
> = SingleStoreDropMilestoneBase<TDatabase, TQueryResult, TPreparedQueryHKT, true, never>; | ||
|
||
export interface SingleStoreDropMilestoneConfig { | ||
milestone: string; | ||
database?: string | undefined; | ||
} | ||
|
||
export type SingleStoreDropMilestonePrepare<T extends AnySingleStoreDropMilestoneBase> = PreparedQueryKind< | ||
T['_']['preparedQueryHKT'], | ||
SingleStorePreparedQueryConfig & { | ||
execute: SingleStoreQueryResultKind<T['_']['queryResult'], never>; | ||
iterator: never; | ||
}, | ||
true | ||
>; | ||
|
||
type SingleStoreDropMilestoneDynamic<T extends AnySingleStoreDropMilestoneBase> = SingleStoreDropMilestone< | ||
T['_']['milestone'], | ||
T['_']['queryResult'], | ||
T['_']['preparedQueryHKT'] | ||
>; | ||
|
||
type AnySingleStoreDropMilestoneBase = SingleStoreDropMilestoneBase<any, any, any, any, any>; | ||
|
||
export interface SingleStoreDropMilestoneBase< | ||
TMilestone extends string, | ||
TQueryResult extends SingleStoreQueryResultHKT, | ||
TPreparedQueryHKT extends PreparedQueryHKTBase, | ||
TDynamic extends boolean = false, | ||
TExcludedMethods extends string = never, | ||
> extends QueryPromise<SingleStoreQueryResultKind<TQueryResult, never>> { | ||
readonly _: { | ||
readonly milestone: TMilestone; | ||
readonly queryResult: TQueryResult; | ||
readonly preparedQueryHKT: TPreparedQueryHKT; | ||
readonly dynamic: TDynamic; | ||
readonly excludedMethods: TExcludedMethods; | ||
}; | ||
} | ||
|
||
export class SingleStoreDropMilestoneBase< | ||
TMilestone extends string, | ||
TQueryResult extends SingleStoreQueryResultHKT, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
TPreparedQueryHKT extends PreparedQueryHKTBase, | ||
TDynamic extends boolean = false, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
TExcludedMethods extends string = never, | ||
> extends QueryPromise<SingleStoreQueryResultKind<TQueryResult, never>> implements SQLWrapper { | ||
static readonly [entityKind]: string = 'SingleStoreDropMilestone'; | ||
|
||
private config: SingleStoreDropMilestoneConfig; | ||
|
||
constructor( | ||
private milestone: TMilestone, | ||
private session: SingleStoreSession, | ||
private dialect: SingleStoreDialect, | ||
) { | ||
super(); | ||
this.config = { milestone }; | ||
} | ||
|
||
// TODO(singlestore): docs | ||
for(database: string): SingleStoreDropMilestoneWithout<this, TDynamic, 'for'> { | ||
this.config.database = database; | ||
return this as any; | ||
} | ||
|
||
/** @internal */ | ||
getSQL(): SQL { | ||
return this.dialect.buildDropMilestoneQuery(this.config); | ||
} | ||
|
||
toSQL(): Query { | ||
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL()); | ||
return rest; | ||
} | ||
|
||
prepare(): SingleStoreDropMilestonePrepare<this> { | ||
return this.session.prepareQuery( | ||
this.dialect.sqlToQuery(this.getSQL()), | ||
undefined, | ||
) as SingleStoreDropMilestonePrepare<this>; | ||
} | ||
|
||
override execute: ReturnType<this['prepare']>['execute'] = (placeholderValues) => { | ||
return this.prepare().execute(placeholderValues); | ||
}; | ||
|
||
private createIterator = (): ReturnType<this['prepare']>['iterator'] => { | ||
const self = this; | ||
return async function*(placeholderValues) { | ||
yield* self.prepare().iterator(placeholderValues); | ||
}; | ||
}; | ||
|
||
iterator = this.createIterator(); | ||
|
||
$dynamic(): SingleStoreDropMilestoneDynamic<this> { | ||
return this as any; | ||
} | ||
} |