drizzle-orm-pg
Advanced tools
Comparing version 0.15.0-7d17618 to 0.15.0-88523f9
@@ -161,5 +161,6 @@ "use strict"; | ||
const tableName = table[table_1.PgTable.Symbol.Name]; | ||
const tableSchema = table[table_1.PgTable.Symbol.Schema]; | ||
const origTableName = table[table_1.PgTable.Symbol.OriginalName]; | ||
const alias = tableName === origTableName ? undefined : tableAlias; | ||
joinsArray.push((0, sql_1.sql) `${sql_1.sql.raw(joinMeta.joinType)} join ${new sql_1.Name(origTableName)} ${alias && new sql_1.Name(alias)} on ${joinMeta.on}`); | ||
joinsArray.push((0, sql_1.sql) `${sql_1.sql.raw(joinMeta.joinType)} join ${tableSchema ? new sql_1.Name(tableSchema) : sql_1.sql.raw('')}${sql_1.sql.raw(tableSchema ? '.' : '')}${new sql_1.Name(origTableName)} ${alias && new sql_1.Name(alias)} on ${joinMeta.on}`); | ||
if (index < joinKeys.length - 1) { | ||
@@ -166,0 +167,0 @@ joinsArray.push((0, sql_1.sql) ` `); |
{ | ||
"name": "drizzle-orm-pg", | ||
"version": "0.15.0-7d17618", | ||
"version": "0.15.0-88523f9", | ||
"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 @@ |
@@ -36,2 +36,12 @@ import { GetColumnData } from 'drizzle-orm'; | ||
}; | ||
declare const isPgSchemaSym: unique symbol; | ||
export interface PgSchema { | ||
} | ||
export declare function isPgSchema(obj: unknown): obj is PgSchema; | ||
export declare function pgSchema<T extends string = string>(schemaName: T): (<TTableName extends string, TColumnsMap extends Record<string, AnyPgColumnBuilder<{}>>>(name: TTableName, columns: TColumnsMap, extraConfig?: ((self: Simplify<{ [Key in keyof TColumnsMap]: import("./columns/common").BuildColumn<TTableName, TColumnsMap[Key]>; }, {}>) => PgTableExtraConfig) | undefined) => PgTableWithColumns<{ | ||
name: TTableName; | ||
columns: Simplify<{ [Key in keyof TColumnsMap]: import("./columns/common").BuildColumn<TTableName, TColumnsMap[Key]>; }, {}>; | ||
}>) & { | ||
[isPgSchemaSym]: boolean; | ||
}; | ||
export declare function pgTable<TTableName extends string, TColumnsMap extends Record<string, AnyPgColumnBuilder>>(name: TTableName, columns: TColumnsMap, extraConfig?: (self: BuildColumns<TTableName, TColumnsMap>) => PgTableExtraConfig): PgTableWithColumns<{ | ||
@@ -41,1 +51,2 @@ name: TTableName; | ||
}>; | ||
export {}; |
44
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.pgSchema = exports.isPgSchema = 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,5 +36,16 @@ PgTable.Symbol = Object.assign(table_1.Table.Symbol, { | ||
Checks: exports.Checks, | ||
ExtraConfig: exports.ExtraConfig, | ||
}); | ||
function pgTable(name, columns, extraConfig) { | ||
const rawTable = new PgTable(name); | ||
const isPgSchemaSym = Symbol('isPgSchema'); | ||
function isPgSchema(obj) { | ||
return !!obj && typeof obj === 'function' && isPgSchemaSym in obj; | ||
} | ||
exports.isPgSchema = isPgSchema; | ||
function pgSchema(schemaName) { | ||
const columnFactory = (name, columns, extraConfig) => pgTableWithSchema(name, columns, schemaName, extraConfig); | ||
return Object.assign(columnFactory, { [isPgSchemaSym]: true }); | ||
} | ||
exports.pgSchema = pgSchema; | ||
function pgTableWithSchema(name, columns, schema, extraConfig) { | ||
const rawTable = new PgTable(name, schema); | ||
const builtColumns = Object.fromEntries(Object.entries(columns).map(([name, colBuilder]) => { | ||
@@ -50,18 +62,10 @@ const column = colBuilder.build(rawTable); | ||
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; | ||
} | ||
return table; | ||
} | ||
function pgTable(name, columns, extraConfig) { | ||
return pgTableWithSchema(name, columns, undefined, extraConfig); | ||
} | ||
exports.pgTable = pgTable; | ||
//# sourceMappingURL=table.js.map |
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 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; |
38
utils.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.orderSelectedFields = exports.mapUpdateSet = 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) { | ||
@@ -10,0 +46,0 @@ const columns = table[table_1.PgTable.Symbol.Columns]; |
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
227448
3424
0