drizzle-orm-pg
Advanced tools
Comparing version 0.12.0-beta.7 to 0.12.0-beta.8
import { AnyColumn } from 'drizzle-orm'; | ||
import { TableName } from 'drizzle-orm/branded-types'; | ||
import { SQL } from 'drizzle-orm/sql'; | ||
import { GetTableName } from 'drizzle-orm/utils'; | ||
export declare function concat<TColumn extends AnyColumn>(column: TColumn, value: string): SQL<GetTableName<TColumn>>; | ||
export declare function substring<TColumn extends AnyColumn>(column: TColumn, { from, for: _for }: { | ||
export declare function concat<TTableName extends TableName, TColumn extends AnyColumn<TTableName>>(column: TColumn, value: string): SQL<TTableName>; | ||
export declare function substring<TTableName extends TableName, TColumn extends AnyColumn<TTableName>>(column: TColumn, { from, for: _for }: { | ||
from?: number; | ||
for?: number; | ||
}): SQL<GetTableName<TColumn>>; | ||
}): SQL<TTableName>; |
@@ -5,3 +5,4 @@ import { InferColumnTable } from 'drizzle-orm'; | ||
import { AnyPgColumn } from './columns'; | ||
import { AnyPgTable } from './table'; | ||
import { PgUpdateSet } from './queries/update'; | ||
import { AnyPgTable, PgTableWithColumns } from './table'; | ||
interface IndexConfig<TTableName extends TableName, TUnique extends boolean> { | ||
@@ -48,18 +49,24 @@ /** | ||
constructor(name: string, columns: AnyPgColumn<TTableName>[], config?: IndexConfig<TTableName, TUnique>); | ||
build(table: AnyPgTable<TTableName>): Index<TTableName, TUnique>; | ||
build<TTableColumns extends Record<string, AnyPgColumn<TTableName>>>(table: PgTableWithColumns<TTableName, TTableColumns, any>): Index<TTableName, TTableColumns, TUnique>; | ||
} | ||
export declare type AnyIndexBuilder<TTableName extends TableName = TableName> = IndexBuilder<TTableName, any>; | ||
export declare class Index<TTableName extends TableName, TUnique extends boolean> { | ||
export declare class Index<TTableName extends TableName, TTableColumns extends Record<string, AnyPgColumn<TTableName>>, TUnique extends boolean> { | ||
readonly name: string; | ||
readonly table: AnyPgTable<TTableName>; | ||
private tableColumns; | ||
readonly columns: AnyPgColumn<TTableName>[]; | ||
protected typeKeeper: { | ||
tableName: TTableName; | ||
tableColumns: TTableColumns; | ||
unique: TUnique; | ||
}; | ||
readonly config: IndexConfig<TTableName, TUnique>; | ||
constructor(name: string, table: AnyPgTable<TTableName>, columns: AnyPgColumn<TTableName>[], builder: IndexBuilder<TTableName, TUnique>); | ||
constructor(name: string, table: AnyPgTable<TTableName>, tableColumns: TTableColumns, columns: AnyPgColumn<TTableName>[], builder: IndexBuilder<TTableName, TUnique>); | ||
set(values: PgUpdateSet<PgTableWithColumns<TTableName, TTableColumns, {}>>): { | ||
constraintName: string; | ||
set: PgUpdateSet<PgTableWithColumns<TTableName, TTableColumns, {}>>; | ||
}; | ||
} | ||
export declare type AnyIndex = Index<any, any>; | ||
export declare type BuildIndex<T extends AnyIndexBuilder> = T extends IndexBuilder<infer TTableName, infer TUnique> ? Index<TTableName, TUnique> : never; | ||
export declare type AnyIndex = Index<any, any, any>; | ||
export declare type BuildIndex<T extends AnyIndexBuilder, TTableColumns extends Record<string, AnyPgColumn>> = T extends IndexBuilder<infer TTable, infer TUnique> ? Index<TTable, TTableColumns, TUnique> : never; | ||
declare type GetColumnsTable<TColumns> = TColumns extends AnyPgColumn ? InferColumnTable<TColumns> : TColumns extends AnyPgColumn[] ? InferColumnTable<TColumns[number]> : never; | ||
@@ -66,0 +73,0 @@ export declare function index<TColumns extends AnyPgColumn | [AnyPgColumn, ...AnyPgColumn[]], TConfig extends IndexConfig<GetColumnsTable<TColumns>, boolean> = IndexConfig<GetColumnsTable<TColumns>, false>>(name: string, columns: TColumns, config?: TConfig): IndexBuilder<GetColumnsTable<TColumns>, GetIndexConfigUnique<TConfig>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uniqueIndex = exports.index = exports.Index = exports.IndexBuilder = void 0; | ||
const utils_1 = require("drizzle-orm/utils"); | ||
class IndexBuilder { | ||
@@ -11,3 +12,3 @@ constructor(name, columns, config = {}) { | ||
build(table) { | ||
return new Index(this.name, table, this.columns, this); | ||
return new Index(this.name, table, table[utils_1.tableColumns], this.columns, this); | ||
} | ||
@@ -17,8 +18,16 @@ } | ||
class Index { | ||
constructor(name, table, columns, builder) { | ||
constructor(name, table, tableColumns, columns, builder) { | ||
this.name = name; | ||
this.table = table; | ||
this.tableColumns = tableColumns; | ||
this.columns = columns; | ||
this.config = builder.config; | ||
} | ||
// ON CONFLICT ... SET | ||
set(values) { | ||
return { | ||
constraintName: this.name, | ||
set: values, | ||
}; | ||
} | ||
} | ||
@@ -25,0 +34,0 @@ exports.Index = Index; |
{ | ||
"name": "drizzle-orm-pg", | ||
"version": "0.12.0-beta.7", | ||
"version": "0.12.0-beta.8", | ||
"description": "Drizzle ORM package for PostgreSQL database", | ||
@@ -48,3 +48,2 @@ "main": "index.js", | ||
"type-fest": "^2.16.0", | ||
"typescript": "4.8.0-beta", | ||
"uvu": "^0.5.3" | ||
@@ -51,0 +50,0 @@ }, |
@@ -5,3 +5,2 @@ import { GetColumnData } from 'drizzle-orm'; | ||
import { Table } from 'drizzle-orm/table'; | ||
import { GetTableName } from 'drizzle-orm/utils'; | ||
import { Simplify } from 'type-fest'; | ||
@@ -13,9 +12,9 @@ import { AnyCheckBuilder, BuildCheck, Check, CheckBuilder } from './checks'; | ||
export declare type PgTableExtraConfig<TTableName extends TableName> = Record<string, AnyIndexBuilder<TTableName> | CheckBuilder<TTableName> | ForeignKeyBuilder<TTableName, TableName>>; | ||
export declare type AnyConflictConstraintBuilder<TTable extends AnyPgTable> = AnyIndexBuilder<GetTableName<TTable>> | AnyCheckBuilder<GetTableName<TTable>>; | ||
export declare type BuildConflictConstraint<T> = T extends IndexBuilder<any, true> ? BuildIndex<T> : T extends AnyCheckBuilder ? BuildCheck<T> : never; | ||
export declare type AnyConflictConstraintBuilder<TTableName extends TableName> = AnyIndexBuilder<TTableName> | AnyCheckBuilder<TTableName>; | ||
export declare type BuildConflictConstraint<TConstraint, TTableColumns extends Record<string, AnyPgColumn>> = TConstraint extends IndexBuilder<any, true> ? BuildIndex<TConstraint, TTableColumns> : TConstraint extends AnyCheckBuilder ? BuildCheck<TConstraint> : never; | ||
export declare type ConflictConstraintKeyOnly<Key, TType> = TType extends AnyCheckBuilder ? Key : TType extends IndexBuilder<any, infer TUnique> ? TUnique extends true ? Key : never : never; | ||
export declare type BuildConflictConstraints<TConfig extends PgTableExtraConfig<any>> = Simplify<{ | ||
[Key in keyof TConfig as ConflictConstraintKeyOnly<Key, TConfig[Key]>]: BuildConflictConstraint<TConfig[Key]>; | ||
export declare type BuildConflictConstraints<TConfig extends PgTableExtraConfig<any>, TTableColumns extends Record<string, AnyPgColumn>> = Simplify<{ | ||
[Key in keyof TConfig as ConflictConstraintKeyOnly<Key, TConfig[Key]>]: BuildConflictConstraint<TConfig[Key], TTableColumns>; | ||
}>; | ||
export declare type ConflictConstraint<TTableName extends TableName> = Index<TTableName, true> | Check<TTableName>; | ||
export declare type ConflictConstraint<TTableName extends TableName> = Index<TTableName, any, true> | Check<TTableName>; | ||
export declare class PgTable<TName extends TableName, TConflictConstraints extends Record<string | symbol, ConflictConstraint<TableName>>> extends Table<TName> { | ||
@@ -37,2 +36,2 @@ protected typeKeeper: Table<TName>['typeKeeper'] & { | ||
export declare type AnyPgTable<TName extends TableName = TableName> = PgTable<TName, any>; | ||
export declare function pgTable<TTableName extends string, TColumnsMap extends Record<string, AnyPgColumnBuilder>, TExtraConfigCallback extends (self: BuildPgColumns<TableName<TTableName>, TColumnsMap>) => PgTableExtraConfig<TableName<TTableName>> = (self: BuildPgColumns<TableName<TTableName>, TColumnsMap>) => {}>(name: TTableName, columns: TColumnsMap, extraConfig?: TExtraConfigCallback): PgTableWithColumns<TableName<TTableName>, BuildPgColumns<TableName<TTableName>, TColumnsMap>, BuildConflictConstraints<ReturnType<TExtraConfigCallback>>>; | ||
export declare function pgTable<TTableName extends string, TColumnsMap extends Record<string, AnyPgColumnBuilder>, TExtraConfigCallback extends (self: BuildPgColumns<TableName<TTableName>, TColumnsMap>) => PgTableExtraConfig<TableName<TTableName>> = (self: BuildPgColumns<TableName<TTableName>, TColumnsMap>) => {}>(name: TTableName, columns: TColumnsMap, extraConfig?: TExtraConfigCallback): PgTableWithColumns<TableName<TTableName>, BuildPgColumns<TableName<TTableName>, TColumnsMap>, BuildConflictConstraints<ReturnType<TExtraConfigCallback>, BuildPgColumns<TableName<TTableName>, TColumnsMap>>>; |
import { AnyPgColumn } from './columns/common'; | ||
import { AnyPgTable, GetTableConflictConstraints } from './table'; | ||
export declare function getTableColumns<TTable extends AnyPgTable>(table: TTable): AnyPgColumn<import("drizzle-orm/branded-types").TableName<string>, any, import("./branded-types").PgColumnDriverParam<import("./connection").PgColumnDriverDataType>, any, any>[]; | ||
export declare function getTableIndexes<TTable extends AnyPgTable>(table: TTable): import("./indexes").Index<import("drizzle-orm/branded-types").TableName<string>, boolean>[]; | ||
export declare function getTableIndexes<TTable extends AnyPgTable>(table: TTable): import("./indexes").Index<import("drizzle-orm/branded-types").TableName<string>, any, boolean>[]; | ||
export declare function getTableForeignKeys<TTable extends AnyPgTable>(table: TTable): import("./foreign-keys").ForeignKey<import("drizzle-orm/branded-types").TableName<string>, import("drizzle-orm/branded-types").TableName<string>>[]; | ||
export declare function getTableChecks<TTable extends AnyPgTable>(table: TTable): import("./checks").Check<import("drizzle-orm/branded-types").TableName<string>>[]; | ||
export declare function getTableConflictConstraints<TTable extends AnyPgTable>(table: TTable): GetTableConflictConstraints<TTable>; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
189731
121
2752