tcurdt
tcurdt
Explore posts from servers
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
seems like the transaction type is slightly different
PgTransaction<PostgresJsQueryResultHKT, typeof import("foo/src/lib/server/db/schema"), ExtractTablesWithRelations<typeof import("foo/src/lib/server/db/schema")>>
PgTransaction<PostgresJsQueryResultHKT, typeof import("foo/src/lib/server/db/schema"), ExtractTablesWithRelations<typeof import("foo/src/lib/server/db/schema")>>
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
I just tried and switched editors. I had a hunch it might be the reason.
Type 'PgTransaction<PostgresJsQueryResultHKT, typeof import("foo/backend-sveltekit/src/lib/server/db/schema"), ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>>' is not assignable to type 'DB | Transaction | undefined'.
Type 'PgTransaction<PostgresJsQueryResultHKT, typeof import("foo/backend-sveltekit/src/lib/server/db/schema"), ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>>' is not assignable to type 'Transaction'.
Types of property 'schema' are incompatible.
Type '{ fullSchema: Record<string, unknown>; schema: ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>; tableNamesMap: Record<...>; } | undefined' is not assignable to type '{ fullSchema: Record<string, unknown>; schema: Record<string, never>; tableNamesMap: Record<string, string>; } | undefined'.
Type '{ fullSchema: Record<string, unknown>; schema: ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>; tableNamesMap: Record<...>; }' is not assignable to type '{ fullSchema: Record<string, unknown>; schema: Record<string, never>; tableNamesMap: Record<string, string>; }'.
Types of property 'schema' are incompatible.
Type 'ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>' is not assignable to type 'Record<string, never>'.
Property 'tableSessions' is incompatible with index signature.
Type '{ tsName: "tableSessions"; dbName: "sessions"; columns: { id: PgColumn<{ name: "id"; tableName: "sessions"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; ... 6 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; superadminId: PgColumn<.....' is not assignable to type 'never'.
Type 'PgTransaction<PostgresJsQueryResultHKT, typeof import("foo/backend-sveltekit/src/lib/server/db/schema"), ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>>' is not assignable to type 'DB | Transaction | undefined'.
Type 'PgTransaction<PostgresJsQueryResultHKT, typeof import("foo/backend-sveltekit/src/lib/server/db/schema"), ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>>' is not assignable to type 'Transaction'.
Types of property 'schema' are incompatible.
Type '{ fullSchema: Record<string, unknown>; schema: ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>; tableNamesMap: Record<...>; } | undefined' is not assignable to type '{ fullSchema: Record<string, unknown>; schema: Record<string, never>; tableNamesMap: Record<string, string>; } | undefined'.
Type '{ fullSchema: Record<string, unknown>; schema: ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>; tableNamesMap: Record<...>; }' is not assignable to type '{ fullSchema: Record<string, unknown>; schema: Record<string, never>; tableNamesMap: Record<string, string>; }'.
Types of property 'schema' are incompatible.
Type 'ExtractTablesWithRelations<typeof import("foo/backend-sveltekit/src/lib/server/db/schema")>' is not assignable to type 'Record<string, never>'.
Property 'tableSessions' is incompatible with index signature.
Type '{ tsName: "tableSessions"; dbName: "sessions"; columns: { id: PgColumn<{ name: "id"; tableName: "sessions"; dataType: "string"; columnType: "PgText"; data: string; driverParam: string; notNull: true; hasDefault: false; ... 6 more ...; generated: undefined; }, {}, {}>; userId: PgColumn<...>; superadminId: PgColumn<.....' is not assignable to type 'never'.
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
No description
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
The complaint is on the tx? ... you mean, you need to see where it is used?
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
Sure.
async function updateSurveyHash(params: {
tx?: Transaction | DB,
surveyId: SurveyId,
}) : Promise<void> {

const { surveyId, tx = db } = params;
async function updateSurveyHash(params: {
tx?: Transaction | DB,
surveyId: SurveyId,
}) : Promise<void> {

const { surveyId, tx = db } = params;
gives
ts: The expected type comes from property 'tx' which is declared here on type '{ tx?: DB | Transaction | undefined; surveyId: SurveyId; }'
ts: The expected type comes from property 'tx' which is declared here on type '{ tx?: DB | Transaction | undefined; surveyId: SurveyId; }'
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
I guess I just go with the first version for now. But it would be nice to understand the difference that causes this here.
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
I spoke to soon.
export type DB = PostgresJsDatabase<typeof schema>;
// export type DB = PostgresJsDatabase<typeof schema> & { $client: postgres.Sql<NonNullable<unknown>> };

async function updateSurveyHash(params: {
tx?: Transaction | DB,
}) : Promise<void> {

const { tx = db } = params;
export type DB = PostgresJsDatabase<typeof schema>;
// export type DB = PostgresJsDatabase<typeof schema> & { $client: postgres.Sql<NonNullable<unknown>> };

async function updateSurveyHash(params: {
tx?: Transaction | DB,
}) : Promise<void> {

const { tx = db } = params;
The first one works just fine. The 2nd one (with $client) gives
ts: The expected type comes from property 'tx' which is declared here on type '{ tx?: DB | Transaction | undefined; }'
ts: The expected type comes from property 'tx' which is declared here on type '{ tx?: DB | Transaction | undefined; }'
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
That seems to work. Thank you so much. Me and the TS typing system are somehow not getting friendly enough.
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
it suggests object or unknown
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
What's the $client for? And eslint complains about the {}
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
But there seems to be a problem caused by & $client: any;
28 replies
DTDrizzle Team
Created by tcurdt on 1/7/2025 in #help
DB and Transaction types
Thanks, @Mario564 ... When I use typeof db it complains. But this looks better so far.
export type DB = PostgresJsDatabase<typeof schema>;
export type Transaction = PgTransaction<PostgresJsQueryResultHKT, typeof schema>
export type DB = PostgresJsDatabase<typeof schema>;
export type Transaction = PgTransaction<PostgresJsQueryResultHKT, typeof schema>
Not entirely sure why this is better though.
28 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
ok ... that is recent 🙂
39 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
drizzle supports views?
39 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
that does feel counter intuitive to me though ... it seems aggregating as early as possible should scale better ... but that's really just my unsubstantiated gut feeling 🙃
39 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
interesting ... sounds like I need to read up on that difference ... first time I am trying it like that also curious to see if there is a big difference in the execution plan
39 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
but I still don't quite understand the why that approach works and my previous approach doesn't
39 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
man, your utility functions are golden. thanks for those.
39 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
no no, not the _ .. but the T itself if it isn't even used. ...and I also get an type warning despite
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
]
}
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}
]
}
but that sounds more like an eslint config issue.
39 replies
DTDrizzle Team
Created by tcurdt on 10/16/2024 in #help
inArray not working as expected
I don't quite get this
[P in PGCastTypes]: P extends `${infer _T}[]` ? P : never;
[P in PGCastTypes]: P extends `${infer _T}[]` ? P : never;
Why the _T?
39 replies