NoBody
NoBody
DTDrizzle Team
Created by NoBody on 9/28/2023 in #help
Multiple Schema | is not assignable to type 'PostgresJsDatabase'.
just provide the type import dotenv from "dotenv"; import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js"; import postgres from "postgres"; import * as schema from "../schema"; dotenv.config(); class DrizzleInstance { private static instance: PostgresJsDatabase<typeof schema> | null = null; private static queryClient = postgres(process.env.DATABASE_URL); public static get Instance(): PostgresJsDatabase<typeof schema> { return ( this.instance || (this.instance = drizzle(this.queryClient, { schema: { ...schema }, })) ); } } const DrizzleDB = DrizzleInstance.Instance; export default DrizzleDB;
8 replies
DTDrizzle Team
Created by ippo on 9/28/2023 in #help
one to many query
hi angelez, i tried to use this kind of query, with limit 1, while in the db, my selected entity have thousands of relation record then the query starts to be very slow
25 replies
DTDrizzle Team
Created by NoBody on 9/28/2023 in #help
Multiple Schema | is not assignable to type 'PostgresJsDatabase'.
i managed to solve it, anyway, i need to provide schema to be able to use .query.table name API
8 replies
DTDrizzle Team
Created by NoBody on 9/28/2023 in #help
Multiple Schema | is not assignable to type 'PostgresJsDatabase'.
and here's the DB Initialization code import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js"; import postgres from "postgres"; import * as schema from "../schema"; class DrizzleInstance { private static instance: PostgresJsDatabase | null = null; private static queryClient = postgres(process.env.DATABASE_URL); public static get Instance(): PostgresJsDatabase { return ( this.instance || (this.instance = drizzle(this.queryClient, { <---- this line throws error on my vscode schema: { ...schema }, })) ); } } const DrizzleDB = DrizzleInstance.Instance; export default DrizzleDB; am i missing something ?
8 replies
DTDrizzle Team
Created by NoBody on 9/28/2023 in #help
Multiple Schema | is not assignable to type 'PostgresJsDatabase'.
now, i want to create the DB instance using my DB Class, but it gives me an error something like this Type 'PostgresJsDatabase<{ Chain: PgTableWithColumns<{ name: "Chain"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "Chain"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; name: PgCo...' is not assignable to type 'PostgresJsDatabase'. The types of '_.schema' are incompatible between these types. Type 'ExtractTablesWithRelations<{ Chain: PgTableWithColumns<{ name: "Chain"; schema: undefined; columns: { id: PgColumn<{ name: "id"; tableName: "Chain"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; na...' is not assignable to type 'ExtractTablesWithRelations<Record<string, never>>'. Property 'Chain' is incompatible with index signature. Type '{ tsName: "Chain"; dbName: "Chain"; columns: { id: PgColumn<{ name: "id"; tableName: "Chain"; dataType: "number"; columnType: "PgSerial"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, {}, {}>; name: PgColumn<...>; chainId: PgColumn<...>; symbol: PgCo...' is not assignable to type '{ tsName: string; dbName: never; columns: never; relations: Record<string, Relation<string>>; primaryKey: AnyColumn[]; }'. Types of property 'dbName' are incompatible. Type 'string' is not assignable to type 'never'.ts(2322) (property) DrizzleInstance.instance: PostgresJsDatabase
8 replies
DTDrizzle Team
Created by NoBody on 9/28/2023 in #help
Multiple Schema | is not assignable to type 'PostgresJsDatabase'.
then i execute the introspect:pg command, and it works properly, it creates a .sql and schema.ts file however, the schema generated is single file only inside /rootProject/drizzle directory so i split the file manually into /rootProject/src/schema directory then i make one index.ts inside that directory file to export all the .ts schema file here's the code of index.ts file export * from "./chain"; ..... ..... and here's one example of schema that i split chain.ts import { integer, pgTable, serial, text, uniqueIndex, } from "drizzle-orm/pg-core"; export const Chain = pgTable( "Chain", { id: serial("id").primaryKey().notNull(), name: text("name").notNull(), chainId: integer("chainId").notNull(), symbol: text("symbol").notNull(), }, (table) => { return { chainIdKey: uniqueIndex("Chain_chainId_key").on(table.chainId), }; } );
8 replies