Prepared insert statement with customType

When using prepared insert statement with customType the Placeholder object gets passed to the toDriver of the custom type. How do I resolve it? Schema:
export const sessionSchema = pgTable('session', {
id: bigintString('id', { mode: 'bigint' }).primaryKey().$default(() => generateSnowflake()),
// More fields
});
export const sessionSchema = pgTable('session', {
id: bigintString('id', { mode: 'bigint' }).primaryKey().$default(() => generateSnowflake()),
// More fields
});
The custom type:
export const bigintString = customType<{
data: string;
driverData: bigint;
}>({
dataType: () => 'bigint',
toDriver: (value) => {
return BigInt(value);
},
fromDriver: (value) => {
return String(value);
},
});
export const bigintString = customType<{
data: string;
driverData: bigint;
}>({
dataType: () => 'bigint',
toDriver: (value) => {
return BigInt(value);
},
fromDriver: (value) => {
return String(value);
},
});
Prepared statement:
public static readonly preparedUpsertStatement = db
.insert(sessionSchema)
.values({
id: sql.placeholder('id'),
// More fields
})
.onConflictDoUpdate({
target: sessionSchema.id,
set: {
// More fields
},
})
.returning()
.prepare('session_upsert');
public static readonly preparedUpsertStatement = db
.insert(sessionSchema)
.values({
id: sql.placeholder('id'),
// More fields
})
.onConflictDoUpdate({
target: sessionSchema.id,
set: {
// More fields
},
})
.returning()
.prepare('session_upsert');
What gets passed to the toDriver of the custom type:
Placeholder {name: 'id'}
name:
'id'
[[Prototype]]:
Object
constructor:
class Placeholder {\n constructor(name2) {\n this.name = name2;\n }\n static [entityKind] = "Placeholder";\n getSQL() {\n return new SQL([this]);\n }\n}
getSQL:
ƒ getSQL() {\n return new SQL([this]);\n }
[[Prototype]]:
Object
Placeholder {name: 'id'}
name:
'id'
[[Prototype]]:
Object
constructor:
class Placeholder {\n constructor(name2) {\n this.name = name2;\n }\n static [entityKind] = "Placeholder";\n getSQL() {\n return new SQL([this]);\n }\n}
getSQL:
ƒ getSQL() {\n return new SQL([this]);\n }
[[Prototype]]:
Object
0 Replies
No replies yetBe the first to reply to this messageJoin