divramod
divramod
Explore posts from servers
TtRPC
Created by Evan on 9/4/2024 in #❓-help
Generating Types in v11
where you able to find a solution @Evan ?
6 replies
DTDrizzle Team
Created by divramod on 8/9/2024 in #help
how to infer the type of the db for the postgres driver
i tried the code snippet from https://github.com/drizzle-team/drizzle-orm/issues/695#issuecomment-2126704308 but i dont know how to use it. when using it like this:
export const myFunction = async (
db: InferQueryModel
): Promise<{ success: boolean}> => {
// do something with db
}
export const myFunction = async (
db: InferQueryModel
): Promise<{ success: boolean}> => {
// do something with db
}
i get the message
typescript: Generic type 'InferQueryModel' requires between 1 and 2 type arguments.
typescript: Generic type 'InferQueryModel' requires between 1 and 2 type arguments.
but i dont know what and how i should pass to InferQueryModel besides that the code snippet from the github issue gives me the following messages
eslint: Don't use `{}` as a type. `{}` actually means "any non-nullish value".
- If you want a type meaning "any object", you probably want `object` instead.
- If you want a type meaning "any value", you probably want `unknown` instead.
- If you want a type meaning "empty object", you probably want `Record<string, never>` instead.
- If you really want a type meaning "any non-nullish value", you probably want `NonNullable<unknown>` instead. [@typescript-eslint/ban-types]
eslint: Don't use `{}` as a type. `{}` actually means "any non-nullish value".
- If you want a type meaning "any object", you probably want `object` instead.
- If you want a type meaning "any value", you probably want `unknown` instead.
- If you want a type meaning "empty object", you probably want `Record<string, never>` instead.
- If you really want a type meaning "any non-nullish value", you probably want `NonNullable<unknown>` instead. [@typescript-eslint/ban-types]
and
typescript: Type 'QBConfig' does not satisfy the constraint 'true | Record<string, unknown>'.
typescript: Type 'QBConfig' does not satisfy the constraint 'true | Record<string, unknown>'.
import type * as schema from './schema'
import type {
BuildQueryResult,
DBQueryConfig,
ExtractTablesWithRelations,
} from 'drizzle-orm'
import type { Exact } from 'type-fest'

type TSchema = ExtractTablesWithRelations<typeof schema>

type QueryConfig<TableName extends keyof TSchema> = DBQueryConfig<
'one' | 'many',
boolean,
TSchema,
TSchema[TableName]
>

export type InferQueryModel<
TableName extends keyof TSchema,
QBConfig extends Exact<QueryConfig<TableName>, QBConfig> = {} // <-- notice Exact here
> = BuildQueryResult<TSchema, TSchema[TableName], QBConfig>
import type * as schema from './schema'
import type {
BuildQueryResult,
DBQueryConfig,
ExtractTablesWithRelations,
} from 'drizzle-orm'
import type { Exact } from 'type-fest'

type TSchema = ExtractTablesWithRelations<typeof schema>

type QueryConfig<TableName extends keyof TSchema> = DBQueryConfig<
'one' | 'many',
boolean,
TSchema,
TSchema[TableName]
>

export type InferQueryModel<
TableName extends keyof TSchema,
QBConfig extends Exact<QueryConfig<TableName>, QBConfig> = {} // <-- notice Exact here
> = BuildQueryResult<TSchema, TSchema[TableName], QBConfig>
3 replies