drizzle-orm
Advanced tools
Comparing version 0.38.3-791f459 to 0.38.3-7db411e
@@ -863,7 +863,5 @@ import * as V1 from "../_relations.js"; | ||
for (const [k, v] of entries) { | ||
if (colSelectionMode === void 0) | ||
colSelectionMode = v; | ||
else if (v !== void 0 && colSelectionMode !== v) { | ||
throw new Error("Columns cannot be both true and false at the same time"); | ||
} | ||
if (v === void 0) | ||
continue; | ||
colSelectionMode = colSelectionMode || v; | ||
if (v) { | ||
@@ -870,0 +868,0 @@ selectedColumns.push({ |
@@ -667,7 +667,5 @@ import * as V1 from "../_relations.js"; | ||
for (const [k, v] of entries) { | ||
if (colSelectionMode === void 0) | ||
colSelectionMode = v; | ||
else if (v !== void 0 && colSelectionMode !== v) { | ||
throw new Error("Columns cannot be both true and false at the same time"); | ||
} | ||
if (v === void 0) | ||
continue; | ||
colSelectionMode = colSelectionMode || v; | ||
if (v) { | ||
@@ -674,0 +672,0 @@ columnIdentifiers.push( |
@@ -12,3 +12,3 @@ import { type AnyTable, type InferModelFromColumns, Table } from "./table.js"; | ||
static readonly [entityKind]: string; | ||
readonly $brand: 'Relations'; | ||
readonly $brand: 'RelationsV2'; | ||
/** table DB name -> schema table key */ | ||
@@ -26,3 +26,3 @@ readonly tableNamesMap: Record<string, string>; | ||
static readonly [entityKind]: string; | ||
readonly $brand: 'Relation'; | ||
readonly $brand: 'RelationV2'; | ||
fieldName: string; | ||
@@ -46,3 +46,3 @@ sourceColumns: AnyColumn<{ | ||
static readonly [entityKind]: string; | ||
protected $relationBrand: 'One'; | ||
protected $relationBrand: 'OneV2'; | ||
readonly optional: TOptional; | ||
@@ -56,3 +56,3 @@ constructor(targetTable: AnyTable<{ | ||
static readonly [entityKind]: string; | ||
protected $relationBrand: 'Many'; | ||
protected $relationBrand: 'ManyV2'; | ||
constructor(targetTable: AnyTable<{ | ||
@@ -125,21 +125,16 @@ name: TTargetTableName; | ||
export type DBQueryConfig<TRelationType extends 'one' | 'many' = 'one' | 'many', TSchema extends TablesRelationalConfig = TablesRelationalConfig, TTableConfig extends TableRelationalConfig = TableRelationalConfig> = { | ||
config?: TTableConfig['relations']; | ||
columns?: { | ||
[K in keyof TTableConfig['columns']]?: true; | ||
} | { | ||
[K in keyof TTableConfig['columns']]?: false; | ||
}; | ||
[K in keyof TTableConfig['columns']]?: boolean | undefined; | ||
} | undefined; | ||
with?: { | ||
[K in keyof TTableConfig['relations']]?: true | (TTableConfig['relations'][K] extends Relation ? DBQueryConfig<TTableConfig['relations'][K] extends One<string, string> ? 'one' : 'many', TSchema, FindTableInRelationalConfig<TSchema, TTableConfig['relations'][K]['targetTable']>> : never); | ||
}; | ||
extras?: Record<string, SQLWrapper> | ((table: Simplify<AnyTable<TTableConfig> & { | ||
[K in keyof TTableConfig['columns']]: TTableConfig['columns'][K]; | ||
}>, operators: SQLOperator) => Record<string, SQLWrapper>); | ||
offset?: number | Placeholder; | ||
where?: RelationsFilter<TTableConfig['columns']>; | ||
orderBy?: ValueOrArray<AnyColumn | SQL> | ((fields: Simplify<[ | ||
TTableConfig['columns'] | ||
] extends [never] ? {} : TTableConfig['columns']>, operators: OrderByOperators) => ValueOrArray<AnyColumn | SQL>); | ||
[K in keyof TTableConfig['relations']]?: true | (TTableConfig['relations'][K] extends Relation ? DBQueryConfig<TTableConfig['relations'][K] extends One<string, string> ? 'one' : 'many', TSchema, FindTableInRelationalConfig<TSchema, TTableConfig['relations'][K]['targetTable']>> : never) | undefined; | ||
} | undefined; | ||
extras?: Record<string, SQLWrapper> | ((table: Simplify<AnyTable<TTableConfig> & TTableConfig['columns']>, operators: SQLOperator) => Record<string, SQLWrapper>) | undefined; | ||
offset?: number | Placeholder | undefined; | ||
where?: RelationsFilter<TTableConfig['columns']> | undefined; | ||
orderBy?: { | ||
[K in keyof TTableConfig['columns']]?: 'asc' | 'desc' | undefined; | ||
} | ((fields: Simplify<AnyTable<TTableConfig> & TTableConfig['columns']>, operators: OrderByOperators) => ValueOrArray<AnyColumn | SQL>) | undefined; | ||
} & (TRelationType extends 'many' ? { | ||
limit?: number | Placeholder; | ||
limit?: number | Placeholder | undefined; | ||
} : {}); | ||
@@ -331,3 +326,3 @@ export interface TableRelationalConfig { | ||
export declare function defineRelations<TSchema extends Record<string, unknown>, TConfig extends RelationsBuilderConfig<TTables>, TTables extends Record<string, Table> = ExtractTablesFromSchema<TSchema>>(schema: TSchema, relations: (helpers: RelationsBuilder<TTables>) => TConfig): Relations<TSchema, TTables, TConfig>; | ||
export type WithContainer<TRelatedTables extends Record<string, Table>> = { | ||
export type WithContainer<TRelatedTables extends Record<string, Table> = Record<string, Table>> = { | ||
with?: { | ||
@@ -344,7 +339,7 @@ [K in keyof TRelatedTables]?: boolean | DBQueryConfig; | ||
}; | ||
export type OrderBy = ValueOrArray<AnyColumn | SQL> | ((fields: Record<string, Column>, operators: OrderByOperators) => ValueOrArray<AnyColumn | SQL>); | ||
export type Extras = Record<string, SQL> | ((fields: Record<string, Column>, operators: SQLOperator) => Record<string, SQL>); | ||
export type OrderBy = Exclude<DBQueryConfig['orderBy'], undefined>; | ||
export type Extras = Exclude<DBQueryConfig['extras'], undefined>; | ||
export declare function relationsFilterToSQL(table: Table, filter: RelationsFilter<Record<string, Column>>): SQL | undefined; | ||
export declare function relationsOrderToSQL(table: Table, orders: ValueOrArray<AnyColumn | SQL> | ((fields: Record<string, Column>, operators: OrderByOperators) => ValueOrArray<AnyColumn | SQL>)): SQL | undefined; | ||
export declare function relationExtrasToSQL(table: Table, extras: Record<string, SQLWrapper> | ((columns: Record<string, Column>, operators: SQLOperator) => Record<string, SQLWrapper>)): { | ||
export declare function relationsOrderToSQL(table: Table, orders: OrderBy): SQL | undefined; | ||
export declare function relationExtrasToSQL(table: Table, extras: Extras): { | ||
sql: SQL<unknown> | undefined; | ||
@@ -351,0 +346,0 @@ selection: { |
@@ -167,3 +167,3 @@ import { getTableUniqueName, IsAlias, Schema, Table } from "./table.js"; | ||
} | ||
static [entityKind] = "Relation"; | ||
static [entityKind] = "RelationV2"; | ||
fieldName; | ||
@@ -177,3 +177,3 @@ sourceColumns; | ||
class One extends Relation { | ||
static [entityKind] = "One"; | ||
static [entityKind] = "OneV2"; | ||
optional; | ||
@@ -206,3 +206,3 @@ constructor(targetTable, config) { | ||
} | ||
static [entityKind] = "Many"; | ||
static [entityKind] = "ManyV2"; | ||
} | ||
@@ -482,4 +482,10 @@ class AggregatedField { | ||
function relationsOrderToSQL(table, orders) { | ||
const data = typeof orders === "function" ? orders(table[Columns], orderByOperators) : orders; | ||
return is(data, SQL) ? data : Array.isArray(data) ? data.length ? sql.join(data.map((o) => is(o, SQL) ? o : asc(o)), sql`, `) : void 0 : asc(data); | ||
if (typeof orders === "function") { | ||
const data = orders(table, orderByOperators); | ||
return is(data, SQL) ? data : Array.isArray(data) ? data.length ? sql.join(data.map((o) => is(o, SQL) ? o : asc(o)), sql`, `) : void 0 : is(data, Column) ? asc(data) : void 0; | ||
} | ||
const entries = Object.entries(orders).filter(([_, value]) => value); | ||
if (!entries.length) | ||
return void 0; | ||
return sql.join(entries.map(([column, value]) => (value === "asc" ? asc : desc)(table[Columns][column])), sql`, `); | ||
} | ||
@@ -490,3 +496,3 @@ function relationExtrasToSQL(table, extras) { | ||
for (const [key, extra] of Object.entries( | ||
typeof extras === "function" ? extras(table[Columns], { sql: operators.sql }) : extras | ||
typeof extras === "function" ? extras(table, { sql: operators.sql }) : extras | ||
)) { | ||
@@ -493,0 +499,0 @@ if (!extra) |
@@ -592,7 +592,5 @@ import * as V1 from "../_relations.js"; | ||
for (const [k, v] of entries) { | ||
if (colSelectionMode === void 0) | ||
colSelectionMode = v; | ||
else if (v !== void 0 && colSelectionMode !== v) { | ||
throw new Error("Columns cannot be both true and false at the same time"); | ||
} | ||
if (v === void 0) | ||
continue; | ||
colSelectionMode = colSelectionMode || v; | ||
if (v) { | ||
@@ -599,0 +597,0 @@ selectedColumns.push({ |
@@ -1,2 +0,2 @@ | ||
var version = "0.38.3-791f459"; | ||
var version = "0.38.3-7db411e"; | ||
@@ -3,0 +3,0 @@ declare const compatibilityVersion = 10; |
// package.json | ||
var version = "0.38.3-791f459"; | ||
var version = "0.38.3-7db411e"; | ||
@@ -4,0 +4,0 @@ // src/version.ts |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8786459
84059