drizzle-orm-pg
Advanced tools
Comparing version 0.15.0-dd27c86 to 0.15.0
@@ -5,3 +5,3 @@ import { SQL } from 'drizzle-orm/sql'; | ||
interface IndexConfig { | ||
name: string; | ||
name?: string; | ||
columns: IndexColumn[]; | ||
@@ -39,5 +39,5 @@ /** | ||
export declare class IndexBuilderOn { | ||
private name; | ||
private unique; | ||
constructor(name: string, unique: boolean); | ||
private name?; | ||
constructor(unique: boolean, name?: string | undefined); | ||
on(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder; | ||
@@ -53,3 +53,3 @@ onOnly(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder; | ||
protected $brand: 'PgIndexBuilder'; | ||
constructor(name: string, columns: IndexColumn[], unique: boolean, only: boolean); | ||
constructor(columns: IndexColumn[], unique: boolean, only: boolean, name?: string); | ||
concurrently(): Omit<this, 'concurrently'>; | ||
@@ -75,4 +75,4 @@ using(method: SQL): Omit<this, 'using'>; | ||
}>[] ? TTableName : never; | ||
export declare function index(name: string): IndexBuilderOn; | ||
export declare function uniqueIndex(name: string): IndexBuilderOn; | ||
export declare function index(name?: string): IndexBuilderOn; | ||
export declare function uniqueIndex(name?: string): IndexBuilderOn; | ||
export {}; |
@@ -5,11 +5,11 @@ "use strict"; | ||
class IndexBuilderOn { | ||
constructor(name, unique) { | ||
constructor(unique, name) { | ||
this.unique = unique; | ||
this.name = name; | ||
this.unique = unique; | ||
} | ||
on(...columns) { | ||
return new IndexBuilder(this.name, columns, this.unique, false); | ||
return new IndexBuilder(columns, this.unique, false, this.name); | ||
} | ||
onOnly(...columns) { | ||
return new IndexBuilder(this.name, columns, this.unique, true); | ||
return new IndexBuilder(columns, this.unique, true, this.name); | ||
} | ||
@@ -19,3 +19,3 @@ } | ||
class IndexBuilder { | ||
constructor(name, columns, unique, only) { | ||
constructor(columns, unique, only, name) { | ||
this.config = { | ||
@@ -69,9 +69,9 @@ name, | ||
function index(name) { | ||
return new IndexBuilderOn(name, false); | ||
return new IndexBuilderOn(false, name); | ||
} | ||
exports.index = index; | ||
function uniqueIndex(name) { | ||
return new IndexBuilderOn(name, true); | ||
return new IndexBuilderOn(true, name); | ||
} | ||
exports.uniqueIndex = uniqueIndex; | ||
//# sourceMappingURL=indexes.js.map |
{ | ||
"name": "drizzle-orm-pg", | ||
"version": "0.15.0-dd27c86", | ||
"version": "0.15.0", | ||
"description": "Drizzle ORM package for PostgreSQL database", | ||
@@ -23,3 +23,3 @@ "main": "index.js", | ||
], | ||
"author": "", | ||
"author": "Drizzle Team", | ||
"license": "Apache-2.0", | ||
@@ -26,0 +26,0 @@ "bugs": { |
@@ -209,11 +209,11 @@ <div align='center'> | ||
// explicit foreign key with 1 column | ||
countryFk: foreignKey(() => ({ | ||
countryFk: foreignKey({ | ||
columns: [cities.countryId], | ||
foreignColumns: [countries.id], | ||
})), | ||
}), | ||
// explicit foreign key with multiple columns | ||
countryIdNameFk: foreignKey(() => ({ | ||
countryIdNameFk: foreignKey({ | ||
columns: [cities.countryId, cities.countryName], | ||
foreignColumns: [countries.id, countries.name], | ||
})), | ||
}), | ||
})); | ||
@@ -220,0 +220,0 @@ |
27
table.js
"use strict"; | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pgTable = exports.PgTable = exports.Checks = exports.ForeignKeys = exports.Indexes = void 0; | ||
exports.pgTable = exports.PgTable = exports.Checks = exports.ExtraConfig = exports.ForeignKeys = exports.Indexes = void 0; | ||
const table_1 = require("drizzle-orm/table"); | ||
const checks_1 = require("./checks"); | ||
const foreign_keys_1 = require("./foreign-keys"); | ||
const indexes_1 = require("./indexes"); | ||
/** @internal */ | ||
@@ -14,2 +11,4 @@ exports.Indexes = Symbol('Indexes'); | ||
/** @internal */ | ||
exports.ExtraConfig = Symbol('ExtraConfig'); | ||
/** @internal */ | ||
exports.Checks = Symbol('Checks'); | ||
@@ -25,6 +24,8 @@ class PgTable extends table_1.Table { | ||
this[_c] = {}; | ||
/** @internal */ | ||
this[_d] = undefined; | ||
} | ||
} | ||
exports.PgTable = PgTable; | ||
table_1.Table.Symbol.Columns, _a = exports.Indexes, _b = exports.ForeignKeys, _c = exports.Checks; | ||
table_1.Table.Symbol.Columns, _a = exports.Indexes, _b = exports.ForeignKeys, _c = exports.Checks, _d = exports.ExtraConfig; | ||
/** @internal */ | ||
@@ -35,2 +36,3 @@ PgTable.Symbol = Object.assign(table_1.Table.Symbol, { | ||
Checks: exports.Checks, | ||
ExtraConfig: exports.ExtraConfig, | ||
}); | ||
@@ -50,14 +52,3 @@ function pgTable(name, columns, extraConfig) { | ||
if (extraConfig) { | ||
const builtConfig = extraConfig(table[PgTable.Symbol.Columns]); | ||
Object.entries(builtConfig).forEach(([name, builder]) => { | ||
if (builder instanceof indexes_1.IndexBuilder) { | ||
table[exports.Indexes][name] = builder.build(table); | ||
} | ||
else if (builder instanceof checks_1.CheckBuilder) { | ||
table[exports.Checks][name] = builder.build(table); | ||
} | ||
else if (builder instanceof foreign_keys_1.ForeignKeyBuilder) { | ||
table[exports.ForeignKeys][name] = builder.build(table); | ||
} | ||
}); | ||
table[PgTable.Symbol.ExtraConfig] = extraConfig; | ||
} | ||
@@ -64,0 +55,0 @@ return table; |
import { SelectFields, SelectFieldsOrdered } from './operations'; | ||
import { AnyPgTable } from './table'; | ||
import { Check } from './checks'; | ||
import { ForeignKey } from './foreign-keys'; | ||
import { Index } from './indexes'; | ||
export declare function getTableConfig<TTable extends AnyPgTable>(table: TTable): { | ||
columns: import("./columns").AnyPgColumn<{ | ||
tableName: string; | ||
}>[]; | ||
indexes: Index[]; | ||
foreignKeys: ForeignKey[]; | ||
checks: Check[]; | ||
}; | ||
export declare function getTableColumns<TTable extends AnyPgTable>(table: TTable): import("./columns").AnyPgColumn<{ | ||
tableName: string; | ||
}>[]; | ||
export declare function getTableIndexes<TTable extends AnyPgTable>(table: TTable): import("./indexes").Index[]; | ||
export declare function getTableForeignKeys<TTable extends AnyPgTable>(table: TTable): import("./foreign-keys").ForeignKey[]; | ||
export declare function getTableChecks<TTable extends AnyPgTable>(table: TTable): import("./checks").Check[]; | ||
export declare const apiVersion: number; | ||
export declare function getTableIndexes<TTable extends AnyPgTable>(table: TTable): Index[]; | ||
export declare function getTableForeignKeys<TTable extends AnyPgTable>(table: TTable): ForeignKey[]; | ||
export declare function getTableChecks<TTable extends AnyPgTable>(table: TTable): Check[]; | ||
export declare type Assume<T, U> = T extends U ? T : U; | ||
export declare function orderSelectedFields(fields: SelectFields, pathPrefix?: string[]): SelectFieldsOrdered; |
39
utils.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.orderSelectedFields = exports.mapUpdateSet = exports.apiVersion = exports.getTableChecks = exports.getTableForeignKeys = exports.getTableIndexes = exports.getTableColumns = void 0; | ||
exports.orderSelectedFields = exports.mapUpdateSet = exports.getTableChecks = exports.getTableForeignKeys = exports.getTableIndexes = exports.getTableColumns = exports.getTableConfig = void 0; | ||
const drizzle_orm_1 = require("drizzle-orm"); | ||
@@ -8,2 +8,38 @@ const sql_1 = require("drizzle-orm/sql"); | ||
const table_1 = require("./table"); | ||
const checks_1 = require("./checks"); | ||
const foreign_keys_1 = require("./foreign-keys"); | ||
const indexes_1 = require("./indexes"); | ||
function getTableConfig(table) { | ||
const columns = getTableColumns(table); | ||
const indexes = []; | ||
const checks = []; | ||
const foreignKeys = getTableForeignKeys(table); | ||
const extraConfig = table[table_1.PgTable.Symbol.ExtraConfig]; | ||
if (typeof extraConfig === 'undefined') | ||
return { | ||
columns, | ||
indexes, | ||
foreignKeys, | ||
checks, | ||
}; | ||
const builtConfig = extraConfig(table[table_1.PgTable.Symbol.Columns]); | ||
Object.entries(builtConfig).forEach(([_, builder]) => { | ||
if (builder instanceof indexes_1.IndexBuilder) { | ||
indexes.push(builder.build(table)); | ||
} | ||
else if (builder instanceof checks_1.CheckBuilder) { | ||
checks.push(builder.build(table)); | ||
} | ||
else if (builder instanceof foreign_keys_1.ForeignKeyBuilder) { | ||
foreignKeys.push(builder.build(table)); | ||
} | ||
}); | ||
return { | ||
columns: getTableColumns(table), | ||
indexes, | ||
foreignKeys, | ||
checks, | ||
}; | ||
} | ||
exports.getTableConfig = getTableConfig; | ||
function getTableColumns(table) { | ||
@@ -33,3 +69,2 @@ const columns = table[table_1.PgTable.Symbol.Columns]; | ||
exports.getTableChecks = getTableChecks; | ||
exports.apiVersion = 1; | ||
/** @internal */ | ||
@@ -36,0 +71,0 @@ function mapUpdateSet(table, values) { |
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
225086
3398
0