@apisr/drizzle-model 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +23 -1
- package/dist/index.mjs +2 -1
- package/dist/model/builder.d.mts +1 -1
- package/dist/model/config.d.mts +3 -3
- package/dist/model/core/runtime.mjs +1 -1
- package/dist/model/core/where.mjs +3 -3
- package/dist/model/dialect.d.mts +1 -1
- package/dist/model/foreigns.d.mts +7 -0
- package/dist/model/format.d.mts +1 -1
- package/dist/model/index.d.mts +23 -1
- package/dist/model/index.mjs +1 -0
- package/dist/model/methods/exclude.d.mts +1 -1
- package/dist/model/methods/index.d.mts +10 -0
- package/dist/model/methods/insert.d.mts +3 -2
- package/dist/model/methods/levels.d.mts +5 -0
- package/dist/model/methods/query/where.d.mts +4 -4
- package/dist/model/methods/return.d.mts +4 -4
- package/dist/model/methods/select.d.mts +1 -1
- package/dist/model/methods/upsert.d.mts +5 -5
- package/dist/model/model.d.mts +25 -25
- package/dist/model/options.d.mts +5 -5
- package/dist/model/query/operations.d.mts +58 -1
- package/dist/model/query/operations.mjs +12 -0
- package/dist/model/relation.d.mts +2 -2
- package/dist/model/result.d.mts +7 -7
- package/dist/model/shape.d.mts +8 -0
- package/dist/model/table.d.mts +14 -2
- package/dist/types.d.mts +3 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/model/index.ts +14 -0
- package/src/model/methods/index.ts +10 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
import { CockroachDbDialect, ModelDialect, MssqlDialect, MySqlDialect, PgDialect, ReturningIdDialects, SingleStoreDialect, SqlLiteDialect, UnknownDialect } from "./model/dialect.mjs";
|
|
2
|
+
import { AddToValues, AddUnionToValues, Compose, Fallback, RecursiveBooleanRecord, Replace, UnwrapArray } from "./types.mjs";
|
|
3
|
+
import { IsTable, NormalizeTable, TableColumn, TableColumns, TableInsertModel, TableInsertValues, TableOneRelationsTableName, TableOutput, TableRelationsTableName } from "./model/table.mjs";
|
|
4
|
+
import { MethodInsertValue, MethodWithInsertValue } from "./model/methods/insert.mjs";
|
|
5
|
+
import { MethodUpdateValue } from "./model/methods/update.mjs";
|
|
6
|
+
import { MethodUpsertContext, MethodUpsertContextFunction, MethodUpsertUpdate, MethodUpsertUpdateValue, MethodUpsertUpdateWhere, MethodUpsertValue } from "./model/methods/upsert.mjs";
|
|
7
|
+
import { ApplyRelationCardinality, RelationKind, RelationMeta, RelationTargetRow, ResolveRelationSelection, ResolveSingleRelation, TargetTable } from "./model/relation.mjs";
|
|
8
|
+
import { MethodWithResult, MethodWithValue } from "./model/methods/with.mjs";
|
|
9
|
+
import { ComposeModelOptions, MergeModelOptionsMethods, ModelMethodsFactory, ModelOptionFormat, ModelOptions, ResolveOptionsFormat, ResolveOptionsMethods } from "./model/options.mjs";
|
|
10
|
+
import { ModelFormatValue } from "./model/format.mjs";
|
|
11
|
+
import { MethodSelectResult, MethodSelectValue, ResolveMethodSelectValue } from "./model/methods/select.mjs";
|
|
12
|
+
import { MethodExcludeResult, MethodExcludeValue, ResolveMethodExcludeValue } from "./model/methods/exclude.mjs";
|
|
13
|
+
import { GetPrimarySerialOrDefaultKeys, MethodReturnResult, PrimaryKeyKeys } from "./model/methods/return.mjs";
|
|
14
|
+
import { ModelMutateResult, ModelQueryResult } from "./model/result.mjs";
|
|
15
|
+
import { Model, ModelBase, ModelIdentifier, ModelMethods, ModelQueryMethods } from "./model/model.mjs";
|
|
16
|
+
import { BoolOps, ColumnOps, ColumnOpsBase, ColumnValue, DateOps, DrizzleColumnDataType, EscapedValue, JsonOps, LogicalOps, NumberOps, StringOps, TypeOps, esc } from "./model/query/operations.mjs";
|
|
17
|
+
import { MethodIncludeIdentifier } from "./model/methods/include.mjs";
|
|
18
|
+
import { MethodWhereColumns, MethodWhereRelations, MethodWhereValue, RelationWhere } from "./model/methods/query/where.mjs";
|
|
19
|
+
import { ModelConfig } from "./model/config.mjs";
|
|
1
20
|
import { modelBuilder } from "./model/builder.mjs";
|
|
21
|
+
import { ModelForegins } from "./model/foreigns.mjs";
|
|
22
|
+
import { ModelFirstLevelMethods, ModelLevelMethods } from "./model/methods/levels.mjs";
|
|
23
|
+
import { ModelShape } from "./model/shape.mjs";
|
|
2
24
|
import "./model/index.mjs";
|
|
3
|
-
export { modelBuilder };
|
|
25
|
+
export { AddToValues, AddUnionToValues, ApplyRelationCardinality, BoolOps, CockroachDbDialect, ColumnOps, ColumnOpsBase, ColumnValue, Compose, ComposeModelOptions, DateOps, DrizzleColumnDataType, EscapedValue, Fallback, GetPrimarySerialOrDefaultKeys, IsTable, JsonOps, LogicalOps, MergeModelOptionsMethods, MethodExcludeResult, MethodExcludeValue, MethodIncludeIdentifier, MethodInsertValue, MethodReturnResult, MethodSelectResult, MethodSelectValue, MethodUpdateValue, MethodUpsertContext, MethodUpsertContextFunction, MethodUpsertUpdate, MethodUpsertUpdateValue, MethodUpsertUpdateWhere, MethodUpsertValue, MethodWhereColumns, MethodWhereRelations, MethodWhereValue, MethodWithInsertValue, MethodWithResult, MethodWithValue, Model, ModelBase, ModelConfig, ModelDialect, ModelFirstLevelMethods, ModelForegins, ModelFormatValue, ModelIdentifier, ModelLevelMethods, ModelMethods, ModelMethodsFactory, ModelMutateResult, ModelOptionFormat, ModelOptions, ModelQueryMethods, ModelQueryResult, ModelShape, MssqlDialect, MySqlDialect, NormalizeTable, NumberOps, PgDialect, PrimaryKeyKeys, RecursiveBooleanRecord, RelationKind, RelationMeta, RelationTargetRow, RelationWhere, Replace, ResolveMethodExcludeValue, ResolveMethodSelectValue, ResolveOptionsFormat, ResolveOptionsMethods, ResolveRelationSelection, ResolveSingleRelation, ReturningIdDialects, SingleStoreDialect, SqlLiteDialect, StringOps, TableColumn, TableColumns, TableInsertModel, TableInsertValues, TableOneRelationsTableName, TableOutput, TableRelationsTableName, TargetTable, TypeOps, UnknownDialect, UnwrapArray, esc, modelBuilder };
|
package/dist/index.mjs
CHANGED
package/dist/model/builder.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModelDialect } from "./dialect.mjs";
|
|
2
2
|
import { ModelOptions } from "./options.mjs";
|
|
3
|
-
import { ModelConfig } from "./config.mjs";
|
|
4
3
|
import { Model } from "./model.mjs";
|
|
4
|
+
import { ModelConfig } from "./config.mjs";
|
|
5
5
|
import { AnyRelations, EmptyRelations } from "drizzle-orm";
|
|
6
6
|
|
|
7
7
|
//#region src/model/builder.d.ts
|
package/dist/model/config.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IsTable, TableOutput } from "./table.mjs";
|
|
2
1
|
import { ModelDialect } from "./dialect.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { MethodWhereValue } from "./methods/query/where.mjs";
|
|
2
|
+
import { IsTable, TableOutput } from "./table.mjs";
|
|
5
3
|
import { ModelOptions, ResolveOptionsFormat } from "./options.mjs";
|
|
6
4
|
import { GetPrimarySerialOrDefaultKeys } from "./methods/return.mjs";
|
|
5
|
+
import { DrizzleColumnDataType } from "./query/operations.mjs";
|
|
6
|
+
import { MethodWhereValue } from "./methods/query/where.mjs";
|
|
7
7
|
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
8
8
|
|
|
9
9
|
//#region src/model/config.d.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { buildSelectProjection } from "./projection.mjs";
|
|
1
2
|
import { MutateResult, QueryResult } from "./thenable.mjs";
|
|
2
3
|
import { applyExclude, applyFormat, applySelect } from "./transform.mjs";
|
|
3
|
-
import { buildSelectProjection } from "./projection.mjs";
|
|
4
4
|
import { compileWhere } from "./where.mjs";
|
|
5
5
|
import { runWithJoins } from "./with.mjs";
|
|
6
6
|
import { and } from "drizzle-orm";
|
|
@@ -96,7 +96,7 @@ function compileColumnValue(column, value) {
|
|
|
96
96
|
const sub = v.and.map((item) => compileColumnValue(column, item)).filter(Boolean);
|
|
97
97
|
if (sub.length) pushIf(and(...sub));
|
|
98
98
|
}
|
|
99
|
-
if (!parts.length) return
|
|
99
|
+
if (!parts.length) return;
|
|
100
100
|
return parts.length === 1 ? parts[0] : and(...parts);
|
|
101
101
|
}
|
|
102
102
|
return eq(column, value);
|
|
@@ -113,11 +113,11 @@ function compileWhereObject(fields, where) {
|
|
|
113
113
|
}
|
|
114
114
|
if (value && typeof value === "object") throw new Error(`Relation where is not implemented yet for key '${key}'.`);
|
|
115
115
|
}
|
|
116
|
-
if (!parts.length) return
|
|
116
|
+
if (!parts.length) return;
|
|
117
117
|
return parts.length === 1 ? parts[0] : and(...parts);
|
|
118
118
|
}
|
|
119
119
|
function compileWhere(fields, where) {
|
|
120
|
-
if (!where) return
|
|
120
|
+
if (!where) return;
|
|
121
121
|
if (typeof where === "object" && where && !isPromiseLike(where)) {
|
|
122
122
|
if (where.$model === "model") throw new Error("Model-as-where is not implemented yet.");
|
|
123
123
|
if (where.getSQL) return where;
|
package/dist/model/dialect.d.mts
CHANGED
|
@@ -9,4 +9,4 @@ type MssqlDialect = "MSSQL";
|
|
|
9
9
|
type CockroachDbDialect = "CockroachDB";
|
|
10
10
|
type ReturningIdDialects = MySqlDialect | SingleStoreDialect | CockroachDbDialect;
|
|
11
11
|
//#endregion
|
|
12
|
-
export { ModelDialect, ReturningIdDialects };
|
|
12
|
+
export { CockroachDbDialect, ModelDialect, MssqlDialect, MySqlDialect, PgDialect, ReturningIdDialects, SingleStoreDialect, SqlLiteDialect, UnknownDialect };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ModelDialect } from "./dialect.mjs";
|
|
2
|
+
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
3
|
+
|
|
4
|
+
//#region src/model/foreigns.d.ts
|
|
5
|
+
type ModelForegins<TSchema extends TablesRelationalConfig, TTable extends TableRelationalConfig, TDialect extends ModelDialect> = {};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { ModelForegins };
|
package/dist/model/format.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
//#region src/model/format.d.ts
|
|
2
|
-
type ModelFormatValue<TValue extends Record<string, any>, TFormat extends Record<string, any> | undefined> = TFormat extends undefined ? TValue : TValue extends (infer TItem)[] ?
|
|
2
|
+
type ModelFormatValue<TValue extends Record<string, any>, TFormat extends Record<string, any> | undefined> = TFormat extends undefined ? TValue : TValue extends (infer TItem)[] ? TItem extends Record<string, any> ? ModelFormatValue<TItem, TFormat>[] : TValue : Omit<TValue, keyof TFormat> & TFormat;
|
|
3
3
|
//#endregion
|
|
4
4
|
export { ModelFormatValue };
|
package/dist/model/index.d.mts
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CockroachDbDialect, ModelDialect, MssqlDialect, MySqlDialect, PgDialect, ReturningIdDialects, SingleStoreDialect, SqlLiteDialect, UnknownDialect } from "./dialect.mjs";
|
|
2
|
+
import { IsTable, NormalizeTable, TableColumn, TableColumns, TableInsertModel, TableInsertValues, TableOneRelationsTableName, TableOutput, TableRelationsTableName } from "./table.mjs";
|
|
3
|
+
import { MethodInsertValue, MethodWithInsertValue } from "./methods/insert.mjs";
|
|
4
|
+
import { MethodUpdateValue } from "./methods/update.mjs";
|
|
5
|
+
import { MethodUpsertContext, MethodUpsertContextFunction, MethodUpsertUpdate, MethodUpsertUpdateValue, MethodUpsertUpdateWhere, MethodUpsertValue } from "./methods/upsert.mjs";
|
|
6
|
+
import { ApplyRelationCardinality, RelationKind, RelationMeta, RelationTargetRow, ResolveRelationSelection, ResolveSingleRelation, TargetTable } from "./relation.mjs";
|
|
7
|
+
import { MethodWithResult, MethodWithValue } from "./methods/with.mjs";
|
|
8
|
+
import { ComposeModelOptions, MergeModelOptionsMethods, ModelMethodsFactory, ModelOptionFormat, ModelOptions, ResolveOptionsFormat, ResolveOptionsMethods } from "./options.mjs";
|
|
9
|
+
import { ModelFormatValue } from "./format.mjs";
|
|
10
|
+
import { MethodSelectResult, MethodSelectValue, ResolveMethodSelectValue } from "./methods/select.mjs";
|
|
11
|
+
import { MethodExcludeResult, MethodExcludeValue, ResolveMethodExcludeValue } from "./methods/exclude.mjs";
|
|
12
|
+
import { GetPrimarySerialOrDefaultKeys, MethodReturnResult, PrimaryKeyKeys } from "./methods/return.mjs";
|
|
13
|
+
import { ModelMutateResult, ModelQueryResult } from "./result.mjs";
|
|
14
|
+
import { Model, ModelBase, ModelIdentifier, ModelMethods, ModelQueryMethods } from "./model.mjs";
|
|
15
|
+
import { BoolOps, ColumnOps, ColumnOpsBase, ColumnValue, DateOps, DrizzleColumnDataType, EscapedValue, JsonOps, LogicalOps, NumberOps, StringOps, TypeOps, esc } from "./query/operations.mjs";
|
|
16
|
+
import { MethodIncludeIdentifier } from "./methods/include.mjs";
|
|
17
|
+
import { MethodWhereColumns, MethodWhereRelations, MethodWhereValue, RelationWhere } from "./methods/query/where.mjs";
|
|
18
|
+
import { ModelConfig } from "./config.mjs";
|
|
19
|
+
import { modelBuilder } from "./builder.mjs";
|
|
20
|
+
import { ModelForegins } from "./foreigns.mjs";
|
|
21
|
+
import { ModelFirstLevelMethods, ModelLevelMethods } from "./methods/levels.mjs";
|
|
22
|
+
import "./methods/index.mjs";
|
|
23
|
+
import { ModelShape } from "./shape.mjs";
|
package/dist/model/index.mjs
CHANGED
|
@@ -5,4 +5,4 @@ type ResolveMethodExcludeValue<TValue extends Record<string, any>, TResult exten
|
|
|
5
5
|
type MethodExcludeResult<TValue extends Record<string, any>, TResult extends Record<string, any>> = TResult extends any[] ? TResult extends (infer RItem)[] ? RItem extends Record<string, any> ? ResolveMethodExcludeValue<TValue, RItem>[] : ResolveMethodExcludeValue<TValue, TResult>[] : ResolveMethodExcludeValue<TValue, TResult> : ResolveMethodExcludeValue<TValue, TResult>;
|
|
6
6
|
type MethodExcludeValue<TResult extends Record<string, any>> = MethodSelectValue<TResult>;
|
|
7
7
|
//#endregion
|
|
8
|
-
export { MethodExcludeResult, MethodExcludeValue };
|
|
8
|
+
export { MethodExcludeResult, MethodExcludeValue, ResolveMethodExcludeValue };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MethodInsertValue, MethodWithInsertValue } from "./insert.mjs";
|
|
2
|
+
import { MethodUpdateValue } from "./update.mjs";
|
|
3
|
+
import { MethodUpsertContext, MethodUpsertContextFunction, MethodUpsertUpdate, MethodUpsertUpdateValue, MethodUpsertUpdateWhere, MethodUpsertValue } from "./upsert.mjs";
|
|
4
|
+
import { MethodWithResult, MethodWithValue } from "./with.mjs";
|
|
5
|
+
import { MethodSelectResult, MethodSelectValue, ResolveMethodSelectValue } from "./select.mjs";
|
|
6
|
+
import { MethodExcludeResult, MethodExcludeValue, ResolveMethodExcludeValue } from "./exclude.mjs";
|
|
7
|
+
import { GetPrimarySerialOrDefaultKeys, MethodReturnResult, PrimaryKeyKeys } from "./return.mjs";
|
|
8
|
+
import { MethodIncludeIdentifier } from "./include.mjs";
|
|
9
|
+
import { MethodWhereColumns, MethodWhereRelations, MethodWhereValue, RelationWhere } from "./query/where.mjs";
|
|
10
|
+
import { ModelFirstLevelMethods, ModelLevelMethods } from "./levels.mjs";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { NormalizeTable, TableInsertValues } from "../table.mjs";
|
|
1
|
+
import { IsTable, NormalizeTable, TableInsertValues } from "../table.mjs";
|
|
2
2
|
import { RelationsRecord, TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
3
3
|
|
|
4
4
|
//#region src/model/methods/insert.d.ts
|
|
5
5
|
type MethodInsertValue<TTable extends TableRelationalConfig> = TableInsertValues<NormalizeTable<TTable>>;
|
|
6
|
+
type MethodWithInsertValue<TSchema extends TablesRelationalConfig, TRelations extends RelationsRecord> = { [Key in keyof TRelations]?: TableInsertValues<IsTable<TSchema[TRelations[Key]["targetTableName"]]["table"]>> };
|
|
6
7
|
//#endregion
|
|
7
|
-
export { MethodInsertValue };
|
|
8
|
+
export { MethodInsertValue, MethodWithInsertValue };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { TableColumn, TableColumns, TableOneRelationsTableName } from "../../table.mjs";
|
|
2
|
-
import { MethodIncludeIdentifier } from "../include.mjs";
|
|
3
|
-
import { ColumnValue } from "../../query/operations.mjs";
|
|
4
2
|
import { ModelIdentifier } from "../../model.mjs";
|
|
3
|
+
import { ColumnValue } from "../../query/operations.mjs";
|
|
4
|
+
import { MethodIncludeIdentifier } from "../include.mjs";
|
|
5
5
|
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
6
6
|
import { SQL } from "drizzle-orm/sql";
|
|
7
7
|
|
|
8
8
|
//#region src/model/methods/query/where.d.ts
|
|
9
|
-
type MethodWhereValue<TSchema extends TablesRelationalConfig, TTable extends TableRelationalConfig, TValue = ModelIdentifier<TableOneRelationsTableName<TTable>> | SQL | MethodWhereColumns<TTable> | MethodWhereRelations<TSchema, TTable> | MethodIncludeIdentifier<any>> = TValue extends MethodIncludeIdentifier<true> ? never :
|
|
9
|
+
type MethodWhereValue<TSchema extends TablesRelationalConfig, TTable extends TableRelationalConfig, TValue = ModelIdentifier<TableOneRelationsTableName<TTable>> | SQL | MethodWhereColumns<TTable> | MethodWhereRelations<TSchema, TTable> | MethodIncludeIdentifier<any>> = TValue extends MethodIncludeIdentifier<true> ? never : TValue extends SQL ? TValue : TValue extends ModelIdentifier<TableOneRelationsTableName<TTable>> ? TValue : TValue extends MethodWhereColumns<TTable> ? TValue : TValue extends MethodWhereRelations<TSchema, TTable> ? TValue : never;
|
|
10
10
|
type MethodWhereRelations<TSchema extends TablesRelationalConfig, TTable extends TableRelationalConfig> = { [TableName in keyof TTable["relations"] as TTable["relations"][TableName]["relationType"] extends "many" ? never : TableName]?: RelationWhere<TSchema[TTable["relations"][TableName & string]["targetTableName"]]> };
|
|
11
11
|
type RelationWhere<TTable extends TableRelationalConfig> = MethodWhereColumns<TTable>;
|
|
12
12
|
type MethodWhereColumns<TTable extends TableRelationalConfig> = { [ColumnName in keyof TableColumns<TTable>]?: ColumnValue<TableColumn<ColumnName & string, TTable>> };
|
|
13
13
|
//#endregion
|
|
14
|
-
export { MethodWhereValue };
|
|
14
|
+
export { MethodWhereColumns, MethodWhereRelations, MethodWhereValue, RelationWhere };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ReturningIdDialects } from "../dialect.mjs";
|
|
2
|
-
import { ModelConfig } from "../config.mjs";
|
|
3
2
|
import { ModelFormatValue } from "../format.mjs";
|
|
3
|
+
import { ModelConfig } from "../config.mjs";
|
|
4
4
|
import { Column } from "drizzle-orm";
|
|
5
5
|
import { InferModelFromColumns } from "drizzle-orm/table";
|
|
6
6
|
|
|
7
7
|
//#region src/model/methods/return.d.ts
|
|
8
|
-
type PrimaryKeyKeys<T extends Record<string, Column>> = { [K in keyof T]: T[K][
|
|
8
|
+
type PrimaryKeyKeys<T extends Record<string, Column>> = { [K in keyof T]: T[K]["_"]["isPrimaryKey"] extends true ? K : never }[keyof T];
|
|
9
9
|
type GetPrimarySerialOrDefaultKeys<T extends Record<string, Column>> = { [K in PrimaryKeyKeys<T>]: T[K] };
|
|
10
|
-
type MethodReturnResult<TResultType extends string, TConfig extends ModelConfig> = TConfig["dialect"] extends ReturningIdDialects ? InferModelFromColumns<GetPrimarySerialOrDefaultKeys<TConfig["tableColumns"]>> :
|
|
10
|
+
type MethodReturnResult<TResultType extends string, TConfig extends ModelConfig> = TConfig["dialect"] extends ReturningIdDialects ? InferModelFromColumns<GetPrimarySerialOrDefaultKeys<TConfig["tableColumns"]>> : TResultType extends "many" ? ModelFormatValue<TConfig["tableOutput"], TConfig["optionsFormat"]>[] : ModelFormatValue<TConfig["tableOutput"], TConfig["optionsFormat"]>;
|
|
11
11
|
//#endregion
|
|
12
|
-
export { GetPrimarySerialOrDefaultKeys, MethodReturnResult };
|
|
12
|
+
export { GetPrimarySerialOrDefaultKeys, MethodReturnResult, PrimaryKeyKeys };
|
|
@@ -5,4 +5,4 @@ type ResolveMethodSelectValue<TValue extends Record<string, any>, TResult extend
|
|
|
5
5
|
type MethodSelectResult<TValue extends Record<string, any>, TResult extends Record<string, any> | any[]> = TResult extends any[] ? TResult extends (infer RItem)[] ? RItem extends Record<string, any> ? ResolveMethodSelectValue<TValue, RItem>[] : ResolveMethodSelectValue<TValue, TResult>[] : ResolveMethodSelectValue<TValue, TResult> : ResolveMethodSelectValue<TValue, TResult>;
|
|
6
6
|
type MethodSelectValue<TResult extends object> = TResult extends readonly (infer U)[] ? U extends object ? MethodSelectValue<U> : never : { [Key in keyof TResult]?: UnwrapArray<TResult[Key]> extends object ? MethodSelectValue<UnwrapArray<TResult[Key]>> | boolean : boolean };
|
|
7
7
|
//#endregion
|
|
8
|
-
export { MethodSelectResult, MethodSelectValue };
|
|
8
|
+
export { MethodSelectResult, MethodSelectValue, ResolveMethodSelectValue };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IsTable } from "../table.mjs";
|
|
2
1
|
import { AddUnionToValues } from "../../types.mjs";
|
|
2
|
+
import { IsTable } from "../table.mjs";
|
|
3
3
|
import { MethodInsertValue } from "./insert.mjs";
|
|
4
|
+
import { MethodUpdateValue } from "./update.mjs";
|
|
4
5
|
import { MethodWhereValue } from "./query/where.mjs";
|
|
5
6
|
import { ModelConfig } from "../config.mjs";
|
|
6
|
-
import { MethodUpdateValue } from "./update.mjs";
|
|
7
7
|
import { Column, SQL } from "drizzle-orm";
|
|
8
8
|
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
9
9
|
|
|
@@ -11,10 +11,10 @@ import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relat
|
|
|
11
11
|
type MethodUpsertValue<TConfig extends ModelConfig, TSchema extends TablesRelationalConfig = TConfig["schema"], TTable extends TableRelationalConfig = TConfig["table"]> = {
|
|
12
12
|
insert: MethodInsertValue<TTable>;
|
|
13
13
|
update: MethodUpsertUpdate<TTable>;
|
|
14
|
-
target?:
|
|
14
|
+
target?: TConfig["primaryKeys"] | TConfig["primaryKeys"][] | Column | Column[];
|
|
15
15
|
updateWhere?: MethodUpsertUpdateWhere<TSchema, TTable>;
|
|
16
16
|
};
|
|
17
|
-
type MethodUpsertContext<TTable extends TableRelationalConfig, TFields extends string =
|
|
17
|
+
type MethodUpsertContext<TTable extends TableRelationalConfig, TFields extends string = keyof IsTable<TTable["table"]>["_"]["columns"] & string> = {
|
|
18
18
|
excluded: (field: TFields) => SQL;
|
|
19
19
|
inserted: (field: TFields) => SQL;
|
|
20
20
|
};
|
|
@@ -23,4 +23,4 @@ type MethodUpsertUpdateValue<TTable extends TableRelationalConfig> = AddUnionToV
|
|
|
23
23
|
type MethodUpsertUpdate<TTable extends TableRelationalConfig> = MethodUpsertUpdateValue<TTable> | MethodUpsertContextFunction<TTable, MethodUpsertUpdateValue<TTable>>;
|
|
24
24
|
type MethodUpsertUpdateWhere<TSchema extends TablesRelationalConfig, TTable extends TableRelationalConfig> = MethodUpsertContextFunction<TTable, MethodWhereValue<TSchema, TTable>>;
|
|
25
25
|
//#endregion
|
|
26
|
-
export { MethodUpsertValue };
|
|
26
|
+
export { MethodUpsertContext, MethodUpsertContextFunction, MethodUpsertUpdate, MethodUpsertUpdateValue, MethodUpsertUpdateWhere, MethodUpsertValue };
|
package/dist/model/model.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { ModelDialect } from "./dialect.mjs";
|
|
1
2
|
import { Replace } from "../types.mjs";
|
|
2
|
-
import { MethodWithValue } from "./methods/with.mjs";
|
|
3
3
|
import { MethodInsertValue } from "./methods/insert.mjs";
|
|
4
|
-
import { ModelDialect } from "./dialect.mjs";
|
|
5
|
-
import { MethodWhereValue } from "./methods/query/where.mjs";
|
|
6
|
-
import { ComposeModelOptions, ModelOptions, ResolveOptionsFormat, ResolveOptionsMethods } from "./options.mjs";
|
|
7
|
-
import { ModelConfig } from "./config.mjs";
|
|
8
|
-
import { ModelMutateResult, ModelQueryResult } from "./result.mjs";
|
|
9
4
|
import { MethodUpdateValue } from "./methods/update.mjs";
|
|
10
5
|
import { MethodUpsertValue } from "./methods/upsert.mjs";
|
|
6
|
+
import { MethodWithValue } from "./methods/with.mjs";
|
|
7
|
+
import { ComposeModelOptions, ModelOptions, ResolveOptionsFormat, ResolveOptionsMethods } from "./options.mjs";
|
|
8
|
+
import { ModelMutateResult, ModelQueryResult } from "./result.mjs";
|
|
9
|
+
import { MethodWhereValue } from "./methods/query/where.mjs";
|
|
10
|
+
import { ModelConfig } from "./config.mjs";
|
|
11
11
|
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
12
12
|
|
|
13
13
|
//#region src/model/model.d.ts
|
|
@@ -19,19 +19,23 @@ import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relat
|
|
|
19
19
|
*/
|
|
20
20
|
interface ModelMethods<TConfig extends ModelConfig, TSchema extends TablesRelationalConfig = TConfig["schema"], TTable extends TableRelationalConfig = TConfig["table"], TDialect extends ModelDialect = TConfig["dialect"]> {
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Deletes rows that match the current model query.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
delete(): ModelMutateResult<void, TConfig, "many">;
|
|
25
25
|
/**
|
|
26
26
|
* Fetches the first matching row for the current model query.
|
|
27
27
|
*/
|
|
28
28
|
findFirst(): ModelQueryResult<TConfig["tableOutput"], TConfig>;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Fetches all rows for the current model query.
|
|
31
|
+
*/
|
|
32
|
+
findMany(): ModelQueryResult<TConfig["tableOutput"][], TConfig>;
|
|
33
|
+
/**
|
|
34
|
+
* Includes related entities in the current model query.
|
|
31
35
|
*
|
|
32
|
-
* @param value -
|
|
36
|
+
* @param value - Include configuration for relations
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
include<TValue extends MethodWithValue<TSchema, TTable["relations"]>>(value: TValue): TValue;
|
|
35
39
|
/**
|
|
36
40
|
* Inserts one or many rows into the model table.
|
|
37
41
|
*
|
|
@@ -44,10 +48,6 @@ interface ModelMethods<TConfig extends ModelConfig, TSchema extends TablesRelati
|
|
|
44
48
|
* @param value - Update payload
|
|
45
49
|
*/
|
|
46
50
|
update<TValue extends MethodUpdateValue<TTable>>(value: TValue): ModelMutateResult<void, TConfig, "many">;
|
|
47
|
-
/**
|
|
48
|
-
* Deletes rows that match the current model query.
|
|
49
|
-
*/
|
|
50
|
-
delete(): ModelMutateResult<void, TConfig, "many">;
|
|
51
51
|
/**
|
|
52
52
|
* Inserts or updates rows based on conflict criteria.
|
|
53
53
|
*
|
|
@@ -55,13 +55,19 @@ interface ModelMethods<TConfig extends ModelConfig, TSchema extends TablesRelati
|
|
|
55
55
|
*/
|
|
56
56
|
upsert<TValue extends MethodUpsertValue<TConfig>>(value: TValue): ModelMutateResult<void, TConfig, TValue["insert"] extends any[] ? "many" : "one">;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Adds a where clause to the current model query.
|
|
59
59
|
*
|
|
60
|
-
* @param value -
|
|
60
|
+
* @param value - Where conditions for the model query
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
where(value: MethodWhereValue<TConfig["schema"], TConfig["table"]>): Model<TConfig>;
|
|
63
63
|
}
|
|
64
64
|
interface ModelQueryMethods<TConfig extends ModelConfig> {
|
|
65
|
+
/**
|
|
66
|
+
* Binds a database client to the model.
|
|
67
|
+
*
|
|
68
|
+
* @param db - Database client instance
|
|
69
|
+
*/
|
|
70
|
+
db(db: any): Model<TConfig>;
|
|
65
71
|
/**
|
|
66
72
|
* Extends the current model with additional options.
|
|
67
73
|
*
|
|
@@ -70,12 +76,6 @@ interface ModelQueryMethods<TConfig extends ModelConfig> {
|
|
|
70
76
|
extend<TOptions extends ModelOptions<TConfig["schema"], TConfig["table"], TConfig["dialect"]>>(config: TOptions): Model<Replace<TConfig, {
|
|
71
77
|
options: ComposeModelOptions<TOptions, TConfig["options"]>;
|
|
72
78
|
}>>;
|
|
73
|
-
/**
|
|
74
|
-
* Binds a database client to the model.
|
|
75
|
-
*
|
|
76
|
-
* @param db - Database client instance
|
|
77
|
-
*/
|
|
78
|
-
db(db: any): Model<TConfig>;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Just base represenation of model. This type JUST made for more clearer types, not more...
|
|
@@ -102,4 +102,4 @@ type ModelIdentifier<ModelName> = {
|
|
|
102
102
|
$modelName: ModelName;
|
|
103
103
|
};
|
|
104
104
|
//#endregion
|
|
105
|
-
export { Model, ModelIdentifier };
|
|
105
|
+
export { Model, ModelBase, ModelIdentifier, ModelMethods, ModelQueryMethods };
|
package/dist/model/options.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TableOutput } from "./table.mjs";
|
|
2
|
-
import { Fallback } from "../types.mjs";
|
|
3
1
|
import { ModelDialect } from "./dialect.mjs";
|
|
2
|
+
import { Fallback } from "../types.mjs";
|
|
3
|
+
import { TableOutput } from "./table.mjs";
|
|
4
4
|
import { MethodWhereValue } from "./methods/query/where.mjs";
|
|
5
5
|
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
6
6
|
|
|
@@ -10,8 +10,8 @@ import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relat
|
|
|
10
10
|
*/
|
|
11
11
|
interface ModelOptions<TSchema extends TablesRelationalConfig = TablesRelationalConfig, TTable extends TableRelationalConfig = TableRelationalConfig, TDialect extends ModelDialect = ModelDialect, TSelf extends ModelOptions<any, any, any, TSelf> = ModelOptions<TSchema, TTable, TDialect, any>> {
|
|
12
12
|
format?: ModelOptionFormat<TTable>;
|
|
13
|
-
where?: MethodWhereValue<TSchema, TTable>;
|
|
14
13
|
methods?: ModelMethodsFactory;
|
|
14
|
+
where?: MethodWhereValue<TSchema, TTable>;
|
|
15
15
|
}
|
|
16
16
|
type ComposeModelOptions<O1 extends ModelOptions, O2 extends ModelOptions> = Omit<O1, "format" | "methods"> & {
|
|
17
17
|
format: Fallback<O1["format"], O2["format"]>;
|
|
@@ -21,8 +21,8 @@ type ModelOptionFormat<TTable extends TableRelationalConfig> = {
|
|
|
21
21
|
bivarianceHack(output: TableOutput<TTable>): any;
|
|
22
22
|
}["bivarianceHack"];
|
|
23
23
|
type ModelMethodsFactory = Record<string, any>;
|
|
24
|
-
type ResolveOptionsMethods<TFactory extends ModelMethodsFactory | undefined> =
|
|
24
|
+
type ResolveOptionsMethods<TFactory extends ModelMethodsFactory | undefined> = TFactory extends ModelMethodsFactory ? TFactory : {};
|
|
25
25
|
type ResolveOptionsFormat<TFormat> = TFormat extends ((...args: any[]) => any) ? ReturnType<TFormat> : undefined;
|
|
26
26
|
type MergeModelOptionsMethods<M1 extends ModelMethodsFactory | undefined, M2 extends ModelMethodsFactory | undefined> = M1 extends ModelMethodsFactory ? M2 extends ModelMethodsFactory ? Omit<M2, keyof M1> & M1 : M1 : M2;
|
|
27
27
|
//#endregion
|
|
28
|
-
export { ComposeModelOptions, ModelOptions, ResolveOptionsFormat, ResolveOptionsMethods };
|
|
28
|
+
export { ComposeModelOptions, MergeModelOptionsMethods, ModelMethodsFactory, ModelOptionFormat, ModelOptions, ResolveOptionsFormat, ResolveOptionsMethods };
|
|
@@ -62,5 +62,62 @@ type LogicalOps<TColumn extends Column> = {
|
|
|
62
62
|
type TypeOps<T> = T extends number ? NumberOps : T extends string ? StringOps : T extends boolean ? BoolOps : T extends Date ? DateOps : T extends any[] ? JsonOps<T[number]> : {};
|
|
63
63
|
type ColumnOps<TColumn extends Column, TDataType extends DrizzleColumnDataType<TColumn>> = ColumnOpsBase<TDataType> & TypeOps<TDataType> & LogicalOps<TColumn>;
|
|
64
64
|
type ColumnValue<TColumn extends Column, TDataType extends DrizzleColumnDataType<TColumn> = DrizzleColumnDataType<TColumn>> = ColumnOps<TColumn, TDataType> | EscapedValue<TDataType>;
|
|
65
|
+
/**
|
|
66
|
+
* Escapes a value from the query DSL and forces it to be compiled using
|
|
67
|
+
* a specific comparison operator.
|
|
68
|
+
*
|
|
69
|
+
* This function exists as an explicit escape hatch for cases where:
|
|
70
|
+
* - the default DSL operators are insufficient
|
|
71
|
+
* - Drizzle ORM operators should be used directly
|
|
72
|
+
* - complex types (e.g. Date, objects, custom classes) need safe handling
|
|
73
|
+
*
|
|
74
|
+
* There are two supported forms:
|
|
75
|
+
*
|
|
76
|
+
* 1) Implicit equality (default behavior):
|
|
77
|
+
* ```ts
|
|
78
|
+
* where({ name: esc("Alex") })
|
|
79
|
+
* ```
|
|
80
|
+
* Compiles to:
|
|
81
|
+
* ```ts
|
|
82
|
+
* {
|
|
83
|
+
* eq: "Alex"
|
|
84
|
+
* }
|
|
85
|
+
* // In drizzle: eq(column, "Alex")
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* 2) Explicit operator (Drizzle-style):
|
|
89
|
+
* ```ts
|
|
90
|
+
* where({ age: esc(gte, 18) })
|
|
91
|
+
* ```
|
|
92
|
+
* Compiles to:
|
|
93
|
+
* ```ts
|
|
94
|
+
* gte(column, 18)
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* The column is injected later during query compilation.
|
|
98
|
+
* `esc` does NOT execute the operator immediately.
|
|
99
|
+
*
|
|
100
|
+
* @typeParam T - The value type being compared against the column
|
|
101
|
+
*
|
|
102
|
+
* @param value - Value to compare using implicit equality
|
|
103
|
+
*
|
|
104
|
+
* @returns An internal escaped descriptor consumed by the query compiler
|
|
105
|
+
*/
|
|
106
|
+
declare function esc<T>(value: T): EscapedValue<T>;
|
|
107
|
+
/**
|
|
108
|
+
* Escapes a value from the query DSL and forces it to be compiled using
|
|
109
|
+
* the provided binary operator.
|
|
110
|
+
*
|
|
111
|
+
* This overload allows reuse of Drizzle ORM operators that normally
|
|
112
|
+
* require the column as the first argument.
|
|
113
|
+
*
|
|
114
|
+
* @typeParam T - The value type expected by the operator
|
|
115
|
+
*
|
|
116
|
+
* @param op - A binary comparison operator (e.g. eq, gte, ilike)
|
|
117
|
+
* @param value - Value to pass as the operator's right-hand side
|
|
118
|
+
*
|
|
119
|
+
* @returns An internal escaped descriptor consumed by the query compiler
|
|
120
|
+
*/
|
|
121
|
+
declare function esc<T>(op: (column: any, value: T) => any, value: T): EscapedValue<T>;
|
|
65
122
|
//#endregion
|
|
66
|
-
export { ColumnValue, DrizzleColumnDataType };
|
|
123
|
+
export { BoolOps, ColumnOps, ColumnOpsBase, ColumnValue, DateOps, DrizzleColumnDataType, EscapedValue, JsonOps, LogicalOps, NumberOps, StringOps, TypeOps, esc };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IsTable, TableOutput } from "./table.mjs";
|
|
2
1
|
import { RecursiveBooleanRecord } from "../types.mjs";
|
|
2
|
+
import { IsTable, TableOutput } from "./table.mjs";
|
|
3
3
|
import { ModelIdentifier } from "./model.mjs";
|
|
4
4
|
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
5
5
|
|
|
@@ -65,4 +65,4 @@ type ResolveSingleRelation<Key extends string, Value, TSchema extends TablesRela
|
|
|
65
65
|
*/
|
|
66
66
|
type ResolveRelationSelection<TSelection extends Record<string, any>, TSchema extends TablesRelationalConfig, TTable extends TableRelationalConfig> = { [Key in keyof TSelection as TSelection[Key] extends true | RecursiveBooleanRecord | ModelIdentifier<any> ? Key & string : never]: ResolveSingleRelation<Key & string, TSelection[Key], TSchema, TTable> };
|
|
67
67
|
//#endregion
|
|
68
|
-
export { ResolveRelationSelection };
|
|
68
|
+
export { ApplyRelationCardinality, RelationKind, RelationMeta, RelationTargetRow, ResolveRelationSelection, ResolveSingleRelation, TargetTable };
|
package/dist/model/result.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { ReturningIdDialects } from "./dialect.mjs";
|
|
1
2
|
import { TableOutput } from "./table.mjs";
|
|
2
3
|
import { MethodWithResult, MethodWithValue } from "./methods/with.mjs";
|
|
3
|
-
import { MethodSelectResult, MethodSelectValue } from "./methods/select.mjs";
|
|
4
|
-
import { MethodExcludeResult, MethodExcludeValue } from "./methods/exclude.mjs";
|
|
5
|
-
import { ReturningIdDialects } from "./dialect.mjs";
|
|
6
4
|
import { ResolveOptionsFormat } from "./options.mjs";
|
|
7
|
-
import { ModelConfig } from "./config.mjs";
|
|
8
5
|
import { ModelFormatValue } from "./format.mjs";
|
|
6
|
+
import { MethodSelectResult, MethodSelectValue } from "./methods/select.mjs";
|
|
7
|
+
import { MethodExcludeResult, MethodExcludeValue } from "./methods/exclude.mjs";
|
|
9
8
|
import { MethodReturnResult } from "./methods/return.mjs";
|
|
9
|
+
import { ModelConfig } from "./config.mjs";
|
|
10
10
|
import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relations";
|
|
11
11
|
|
|
12
12
|
//#region src/model/result.d.ts
|
|
@@ -21,11 +21,11 @@ import { TableRelationalConfig, TablesRelationalConfig } from "drizzle-orm/relat
|
|
|
21
21
|
* @typeParam TTable - Relational configuration for the current table
|
|
22
22
|
*/
|
|
23
23
|
interface ModelQueryResult<TResult extends Record<string, any>, TConfig extends ModelConfig, TExcludedKeys extends string = string, TSchema extends TablesRelationalConfig = TConfig["schema"], TTable extends TableRelationalConfig = TConfig["table"], TFormat extends Record<string, any> | undefined = ResolveOptionsFormat<TConfig["options"]["format"]>> extends Promise<ModelFormatValue<TResult, TFormat>> {
|
|
24
|
-
|
|
25
|
-
select<TValue extends MethodSelectValue<TResult>, TExcludeKeys extends string = TExcludedKeys | "select">(value: TValue): ModelQueryResult<MethodSelectResult<TValue, TResult>, TConfig, TExcludeKeys>;
|
|
24
|
+
debug(): any;
|
|
26
25
|
exclude<TValue extends MethodExcludeValue<TResult>, TExcludeKeys extends string = TExcludedKeys | "exclude">(value: TValue): ModelQueryResult<MethodExcludeResult<TValue, TResult>, TConfig, TExcludeKeys>;
|
|
27
26
|
raw<TExcludeKeys extends string = TExcludedKeys | "raw">(): ModelQueryResult<TResult, TConfig, TExcludeKeys, TSchema, TTable, undefined>;
|
|
28
|
-
|
|
27
|
+
select<TValue extends MethodSelectValue<TResult>, TExcludeKeys extends string = TExcludedKeys | "select">(value: TValue): ModelQueryResult<MethodSelectResult<TValue, TResult>, TConfig, TExcludeKeys>;
|
|
28
|
+
with<TValue extends MethodWithValue<TSchema, TTable["relations"]>, TExcludeKeys extends string = TExcludedKeys | "with">(value: TValue): ModelQueryResult<MethodWithResult<TValue, TResult, TSchema, TTable>, TConfig, TExcludeKeys>;
|
|
29
29
|
}
|
|
30
30
|
interface ModelMutateResult<TBaseResult extends Record<string, any> | void, TConfig extends ModelConfig, TResultType extends string = "one"> extends Promise<TBaseResult> {
|
|
31
31
|
return<TValue extends MethodSelectValue<TableOutput<TConfig["table"]>> | undefined, TReturnResult extends MethodReturnResult<TResultType, TConfig> = MethodReturnResult<TResultType, TConfig>, TResult extends Record<string, any> = (TValue extends undefined ? TReturnResult : MethodSelectResult<Exclude<TValue, undefined>, TReturnResult>)>(value?: TConfig["dialect"] extends ReturningIdDialects ? never : TValue): Omit<ModelMutateResult<TResult, TConfig, TResultType>, "with">;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResolveOptionsMethods } from "./options.mjs";
|
|
2
|
+
import { ModelBase, ModelIdentifier } from "./model.mjs";
|
|
3
|
+
import { ModelConfig } from "./config.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/model/shape.d.ts
|
|
6
|
+
type ModelShape<TConfig extends ModelConfig> = ModelIdentifier<TConfig["table"]["name"]> & ModelBase<TConfig> & ResolveOptionsMethods<TConfig["options"]["methods"]>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ModelShape };
|
package/dist/model/table.d.mts
CHANGED
|
@@ -40,7 +40,13 @@ type TableOutput<TTable extends TableRelationalConfig | SchemaEntry | Table> = N
|
|
|
40
40
|
*
|
|
41
41
|
* @typeParam TTable - Relation config, schema entry, or table
|
|
42
42
|
*/
|
|
43
|
-
type NormalizeTable<TTable extends TableRelationalConfig | SchemaEntry | Table> =
|
|
43
|
+
type NormalizeTable<TTable extends TableRelationalConfig | SchemaEntry | Table> = TTable extends TableRelationalConfig ? IsTable<TTable["table"]> : TTable extends SchemaEntry ? IsTable<TTable> : TTable extends Table ? TTable : never;
|
|
44
|
+
/**
|
|
45
|
+
* Collects target table names from all relations.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam TTable - Relational configuration for the table
|
|
48
|
+
*/
|
|
49
|
+
type TableRelationsTableName<TTable extends TableRelationalConfig> = { [K in keyof TTable["relations"]]: TTable["relations"][K]["targetTableName"] }[keyof TTable["relations"]];
|
|
44
50
|
/**
|
|
45
51
|
* Maps non-"many" relations to their target table names.
|
|
46
52
|
*
|
|
@@ -59,6 +65,12 @@ type TableOneRelationsTableName<TTable extends TableRelationalConfig> = TableOne
|
|
|
59
65
|
* @typeParam T - Candidate table type
|
|
60
66
|
*/
|
|
61
67
|
type IsTable<T> = T extends Table ? T : never;
|
|
68
|
+
/**
|
|
69
|
+
* Infers insert model for a Drizzle table.
|
|
70
|
+
*
|
|
71
|
+
* @typeParam TTable - Drizzle table type
|
|
72
|
+
*/
|
|
73
|
+
type TableInsertModel<TTable extends Table> = InferInsertModel<TTable>;
|
|
62
74
|
/**
|
|
63
75
|
* Accepts a single insert payload or a batch of insert payloads.
|
|
64
76
|
*
|
|
@@ -66,4 +78,4 @@ type IsTable<T> = T extends Table ? T : never;
|
|
|
66
78
|
*/
|
|
67
79
|
type TableInsertValues<TTable extends Table> = InferInsertModel<TTable> | InferInsertModel<TTable>[];
|
|
68
80
|
//#endregion
|
|
69
|
-
export { IsTable, NormalizeTable, TableColumn, TableColumns, TableInsertValues, TableOneRelationsTableName, TableOutput };
|
|
81
|
+
export { IsTable, NormalizeTable, TableColumn, TableColumns, TableInsertModel, TableInsertValues, TableOneRelationsTableName, TableOutput, TableRelationsTableName };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
+
type Compose<T, U> = T & U;
|
|
2
3
|
type Fallback<A, B> = A extends undefined ? B : A;
|
|
3
4
|
type Replace<T, R> = Omit<T, keyof R> & R;
|
|
4
5
|
type UnwrapArray<T> = T extends (infer R)[] ? R : T;
|
|
6
|
+
type AddToValues<T extends Record<PropertyKey, any>, A> = { [K in keyof T]: T[K] & A };
|
|
5
7
|
type AddUnionToValues<T extends Record<PropertyKey, any>, A> = { [K in keyof T]: T[K] | A };
|
|
6
8
|
interface RecursiveBooleanRecord {
|
|
7
9
|
[key: string]: boolean | RecursiveBooleanRecord;
|
|
8
10
|
}
|
|
9
11
|
//#endregion
|
|
10
|
-
export { AddUnionToValues, Fallback, RecursiveBooleanRecord, Replace, UnwrapArray };
|
|
12
|
+
export { AddToValues, AddUnionToValues, Compose, Fallback, RecursiveBooleanRecord, Replace, UnwrapArray };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/model/index.ts
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
1
|
export * from "./builder.ts";
|
|
2
|
+
export * from "./config";
|
|
3
|
+
export * from "./dialect.ts";
|
|
4
|
+
export * from "./foreigns.ts";
|
|
5
|
+
export * from "./format.ts";
|
|
6
|
+
// Methods
|
|
7
|
+
export * from "./methods";
|
|
8
|
+
export * from "./model.ts";
|
|
9
|
+
export * from "./options.ts";
|
|
10
|
+
// Query
|
|
11
|
+
export * from "./query/operations.ts";
|
|
12
|
+
export * from "./relation.ts";
|
|
13
|
+
export * from "./result.ts";
|
|
14
|
+
export * from "./shape.ts";
|
|
15
|
+
export * from "./table.ts";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./exclude";
|
|
2
|
+
export * from "./include";
|
|
3
|
+
export * from "./insert";
|
|
4
|
+
export * from "./levels";
|
|
5
|
+
export * from "./query/where";
|
|
6
|
+
export * from "./return";
|
|
7
|
+
export * from "./select";
|
|
8
|
+
export * from "./update";
|
|
9
|
+
export * from "./upsert";
|
|
10
|
+
export * from "./with";
|