pgTable - extra config (primaryKey) issues
I seem to be having some issues with pgTable - which I can't figure out. Could someone lend me a hand as I have been trying all day 🙂
I tried asking in the #orm-beta but not had a response. I'm super stuck and this is blocking my deployment of RQB-V2.
(my code in thread) I seem to be having some issues with pgTable, any time I build with the current beta I get errors related to the extra config. I know I was previously using the now deprecated object notation, and I switched that to the array, but still get the issues. I also tried both with and without the function option, which caused issues too.
I'm super stuck, really need help and don't quite know where to continue. Could someone lend me a hand as I have been trying all day 🙂
1 Reply
TS2769: No overload matches this call.
Overload 1 of 2, '(config: { name?: string; columns: [AnyPgColumn<{ tableName: string; }>, ...AnyPgColumn<{ tableName: string; }>[]]; }): PrimaryKeyBuilder', gave the following error. Type 'ExtraConfigColumn<ColumnBaseConfig<ColumnDataType, string>>' is not assignable to type 'AnyPgColumn<{ tableName: string; }>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the targets properties. The types of 'table._.config.columns' are incompatible between these types.
Type 'Record<string, import(".../drizzle-orm/pg-core/columns/common", { with: { "resoluti
on-mode": "import" } }).PgColumn<import("...' is not assignable to type 'Record<string, import(".../drizzle-orm/pg-core/columns/common").PgColumn<import("...'.
'string' index signatures are incompatible.
Type 'import(".../drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "
import" } }).PgColumn<import("...' is not assignable to type 'import(".../drizzle-orm/pg-core/columns/common").PgColumn<import("...' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.
Overload 2 of 2, '(...columns: AnyPgColumn<{ tableName: string; }>[]): PrimaryKeyBuilder', gave the following error. Object literal may only specify known properties, and 'columns' does not exist in type 'PgColumn<Required<Update<ColumnBaseConfig<ColumnDataType, string>, { tableName: string; }>>, {}, {}>'.
29 primaryKey( { columns: [ table.sourceId, table.competitorId ] } )
TS2769: No overload matches this call.
Overload 1 of 2, '(config: { name?: string; columns: [AnyPgColumn<{ tableName: string; }>, ...AnyPgColumn<{ tableName: string; }>[]]; }): PrimaryKeyBuilder', gave the following error. Type 'ExtraConfigColumn<ColumnBaseConfig<ColumnDataType, string>>' is not assignable to type 'AnyPgColumn<{ tableName: string; }>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the targets properties. The types of 'table._.config.columns' are incompatible between these types.
Type 'Record<string, import(".../drizzle-orm/pg-core/columns/common", { with: { "resoluti
on-mode": "import" } }).PgColumn<import("...' is not assignable to type 'Record<string, import(".../drizzle-orm/pg-core/columns/common").PgColumn<import("...'.
'string' index signatures are incompatible.
Type 'import(".../drizzle-orm/pg-core/columns/common", { with: { "resolution-mode": "
import" } }).PgColumn<import("...' is not assignable to type 'import(".../drizzle-orm/pg-core/columns/common").PgColumn<import("...' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.
Overload 2 of 2, '(...columns: AnyPgColumn<{ tableName: string; }>[]): PrimaryKeyBuilder', gave the following error. Object literal may only specify known properties, and 'columns' does not exist in type 'PgColumn<Required<Update<ColumnBaseConfig<ColumnDataType, string>, { tableName: string; }>>, {}, {}>'.
29 primaryKey( { columns: [ table.sourceId, table.competitorId ] } )
import { encircleId } from '@encircle-marketing/crm.utilities.helpers.custom-db-type-encircle-id'
import { idSchema, typeid } from '@encircle-marketing/crm.utilities.helpers.custom-db-type-typeid'
import { BuildExtraConfigColumns, SQL, sql } from 'drizzle-orm'
import {
customType,
index,
PgColumnBuilderBase,
pgEnum,
pgTable as drizzlePgTable,
PgTableExtraConfigValue,
timestamp,
uniqueIndex
} from 'drizzle-orm/pg-core'
import { getPgColumnBuilders } from 'drizzle-orm/pg-core/columns/all'
export function pgTable<
TTableName extends string,
TColumnsKey extends string,
TColumnsMap extends Record<TColumnsKey, PgColumnBuilderBase>
> (
name: TTableName,
columns: ( columnTypes: AllBuilders ) => TColumnsMap,
extraConfig?: ( self: BuildExtraConfigColumns<TTableName, TColumnsMap, 'pg'> ) => PgTableExtraConfigValue[]
) {
const result = drizzlePgTable(
name,
( db ) => columns( {
...db,
encircleId,
typeid
} ),
( table ) => {
const extra = extraConfig
? extraConfig( table )
: []
return [
...extra
]
}
)
return result
}
import { encircleId } from '@encircle-marketing/crm.utilities.helpers.custom-db-type-encircle-id'
import { idSchema, typeid } from '@encircle-marketing/crm.utilities.helpers.custom-db-type-typeid'
import { BuildExtraConfigColumns, SQL, sql } from 'drizzle-orm'
import {
customType,
index,
PgColumnBuilderBase,
pgEnum,
pgTable as drizzlePgTable,
PgTableExtraConfigValue,
timestamp,
uniqueIndex
} from 'drizzle-orm/pg-core'
import { getPgColumnBuilders } from 'drizzle-orm/pg-core/columns/all'
export function pgTable<
TTableName extends string,
TColumnsKey extends string,
TColumnsMap extends Record<TColumnsKey, PgColumnBuilderBase>
> (
name: TTableName,
columns: ( columnTypes: AllBuilders ) => TColumnsMap,
extraConfig?: ( self: BuildExtraConfigColumns<TTableName, TColumnsMap, 'pg'> ) => PgTableExtraConfigValue[]
) {
const result = drizzlePgTable(
name,
( db ) => columns( {
...db,
encircleId,
typeid
} ),
( table ) => {
const extra = extraConfig
? extraConfig( table )
: []
return [
...extra
]
}
)
return result
}
import { pgTable } from '@encircle-marketing/crm.entities.abstraction'
import { record, recordTableName } from '@encircle-marketing/crm.entities.db.drizzle.schema.record'
import { primaryKey } from 'drizzle-orm/pg-core'
export const recordsToRecords = pgTable(
recordsToRecordsTableName,
( db ) => ( {
sourceId: db.typeid( 'source_id', { type: recordTableName } )
.notNull()
.references( () => record.id ),
competitorId: db.typeid( 'matched_id', { type: recordTableName } )
.notNull()
.references( () => record.id )
} ),
( table ) => [
primaryKey( { columns: [ table.sourceId, table.competitorId ] } )
]
)
import { pgTable } from '@encircle-marketing/crm.entities.abstraction'
import { record, recordTableName } from '@encircle-marketing/crm.entities.db.drizzle.schema.record'
import { primaryKey } from 'drizzle-orm/pg-core'
export const recordsToRecords = pgTable(
recordsToRecordsTableName,
( db ) => ( {
sourceId: db.typeid( 'source_id', { type: recordTableName } )
.notNull()
.references( () => record.id ),
competitorId: db.typeid( 'matched_id', { type: recordTableName } )
.notNull()
.references( () => record.id )
} ),
( table ) => [
primaryKey( { columns: [ table.sourceId, table.competitorId ] } )
]
)