"Seems like the schema generic is missing - did you forget to add it to your DB type?"

how to fix this... i need to use db.query
H
Hussein191d ago
? do i need to pass {schema} to drizzle()? its giving me this huge error
Type 'BetterSQLite3Database<typeof import("/home/h/Desktop/web-app/src/schema")>' is not assignable to type 'BetterSQLite3Database'.
The types of '_.schema' are incompatible between these types.
Type 'ExtractTablesWithRelations<typeof import("/home/h/Desktop/web-app/src/schema")> | undefined' is not assignable to type 'ExtractTablesWithRelations<Record<string, never>> | undefined'.
Type 'ExtractTablesWithRelations<typeof import("/home/h/Desktop/web-app/src/schema")>' is not assignable to type 'ExtractTablesWithRelations<Record<string, never>>'.
Property 'users' is incompatible with index signature.
Type '{ tsName: "users"; dbName: "users"; columns: { id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [...]; baseColumn: never; }, object>; username: SQLiteColumn<...>; password: SQLiteColumn<......' 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)
Type 'BetterSQLite3Database<typeof import("/home/h/Desktop/web-app/src/schema")>' is not assignable to type 'BetterSQLite3Database'.
The types of '_.schema' are incompatible between these types.
Type 'ExtractTablesWithRelations<typeof import("/home/h/Desktop/web-app/src/schema")> | undefined' is not assignable to type 'ExtractTablesWithRelations<Record<string, never>> | undefined'.
Type 'ExtractTablesWithRelations<typeof import("/home/h/Desktop/web-app/src/schema")>' is not assignable to type 'ExtractTablesWithRelations<Record<string, never>>'.
Property 'users' is incompatible with index signature.
Type '{ tsName: "users"; dbName: "users"; columns: { id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "string"; columnType: "SQLiteText"; data: string; driverParam: string; notNull: true; hasDefault: true; enumValues: [...]; baseColumn: never; }, object>; username: SQLiteColumn<...>; password: SQLiteColumn<......' 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)
this is my schema
import {sqliteTable, text} from 'drizzle-orm/sqlite-core'
import {createId} from '@paralleldrive/cuid2'
import {relations} from 'drizzle-orm'

const id = text('id', {length: 128})
.primaryKey()
.$defaultFn(() => createId())

export const users = sqliteTable('users', {
id,
username: text('username', {length: 255}).unique().notNull(),
password: text('password', {length: 255}).notNull(),
profilePicture: text('profile_picture'),
profilePictureAlt: text('pfp_alt')
})

export const usersRelations = relations(users, ({many}) => ({
posts: many(friends)
}))

export const friends = sqliteTable('posts', {
userId: text('user_id'),
friendId: text('friend_id')
})

export const friendsRelations = relations(friends, ({one}) => ({
user: one(users, {
fields: [friends.userId, friends.friendId],
references: [users.id, users.id]
})
}))
import {sqliteTable, text} from 'drizzle-orm/sqlite-core'
import {createId} from '@paralleldrive/cuid2'
import {relations} from 'drizzle-orm'

const id = text('id', {length: 128})
.primaryKey()
.$defaultFn(() => createId())

export const users = sqliteTable('users', {
id,
username: text('username', {length: 255}).unique().notNull(),
password: text('password', {length: 255}).notNull(),
profilePicture: text('profile_picture'),
profilePictureAlt: text('pfp_alt')
})

export const usersRelations = relations(users, ({many}) => ({
posts: many(friends)
}))

export const friends = sqliteTable('posts', {
userId: text('user_id'),
friendId: text('friend_id')
})

export const friendsRelations = relations(friends, ({one}) => ({
user: one(users, {
fields: [friends.userId, friends.friendId],
references: [users.id, users.id]
})
}))
A
Angelelz190d ago
How are you defining the drizzle object?
H
Hussein190d ago
import * as schema from '../../schema'
import Database from 'better-sqlite3'
import {migrate} from 'drizzle-orm/better-sqlite3/migrator'
import {drizzle, type BetterSQLite3Database} from 'drizzle-orm/better-sqlite3'

const sqlite = new Database('sqlite.db')
export const database: BetterSQLite3Database = drizzle(sqlite, {schema})
import * as schema from '../../schema'
import Database from 'better-sqlite3'
import {migrate} from 'drizzle-orm/better-sqlite3/migrator'
import {drizzle, type BetterSQLite3Database} from 'drizzle-orm/better-sqlite3'

const sqlite = new Database('sqlite.db')
export const database: BetterSQLite3Database = drizzle(sqlite, {schema})
i changed this schema according to https://discord.com/channels/1043890932593987624/1111572543556550738/1148828114345021510 so now its
import {primaryKey, sqliteTable, text} from 'drizzle-orm/sqlite-core'
import {createId} from '@paralleldrive/cuid2'
import {relations} from 'drizzle-orm'

const id = text('id', {length: 128})
.primaryKey()
.$defaultFn(() => createId())

export const users = sqliteTable('users', {
id,
username: text('username', {length: 255}).unique().notNull(),
password: text('password', {length: 255}).notNull(),
profilePicture: text('profile_picture'),
profilePictureAlt: text('pfp_alt')
})

export const usersRelations = relations(users, ({many}) => ({
follows: many(follows, {relationName: 'follows'}),
followers: many(follows, {relationName: 'followers'})
}))

export const follows = sqliteTable(
'follows',
{
followerId: id,
followeeId: id
},
(t) => ({
pk: primaryKey(t.followerId, t.followeeId)
})
)

export const followsRelations = relations(follows, ({one}) => ({
follower: one(users, {
fields: [follows.followerId],
references: [users.id],
relationName: 'follows'
}),
followee: one(users, {
fields: [follows.followeeId],
references: [users.id],
relationName: 'followers'
})
}))
import {primaryKey, sqliteTable, text} from 'drizzle-orm/sqlite-core'
import {createId} from '@paralleldrive/cuid2'
import {relations} from 'drizzle-orm'

const id = text('id', {length: 128})
.primaryKey()
.$defaultFn(() => createId())

export const users = sqliteTable('users', {
id,
username: text('username', {length: 255}).unique().notNull(),
password: text('password', {length: 255}).notNull(),
profilePicture: text('profile_picture'),
profilePictureAlt: text('pfp_alt')
})

export const usersRelations = relations(users, ({many}) => ({
follows: many(follows, {relationName: 'follows'}),
followers: many(follows, {relationName: 'followers'})
}))

export const follows = sqliteTable(
'follows',
{
followerId: id,
followeeId: id
},
(t) => ({
pk: primaryKey(t.followerId, t.followeeId)
})
)

export const followsRelations = relations(follows, ({one}) => ({
follower: one(users, {
fields: [follows.followerId],
references: [users.id],
relationName: 'follows'
}),
followee: one(users, {
fields: [follows.followeeId],
references: [users.id],
relationName: 'followers'
})
}))
A
Angelelz190d ago
Try this:
export const database = drizzle(sqlite, {schema})
// or
export const database: BetterSQLite3Database<typeof schema> = drizzle(sqlite, {schema})
export const database = drizzle(sqlite, {schema})
// or
export const database: BetterSQLite3Database<typeof schema> = drizzle(sqlite, {schema})
H
Hussein190d ago
thanks can you help me with this schema
DrizzleError: Failed to run the query 'CREATE TABLE `follows` (
`id` text(128) PRIMARY KEY NOT NULL,
PRIMARY KEY(`id`, `id`)
);
': table "follows" has more than one primary key
DrizzleError: Failed to run the query 'CREATE TABLE `follows` (
`id` text(128) PRIMARY KEY NOT NULL,
PRIMARY KEY(`id`, `id`)
);
': table "follows" has more than one primary key
K
Kilisei174d ago
@Angelelz you saved my sanity Your a chad
Want results from more Discord servers?
Add your server
More Posts
migrate function hangs without any resultI have this in my `migrate.js` file ``` // @ts-check const { drizzle } = require("drizzle-orm/nodeSelect with a join that returns eagerly loaded submodelshey all, is it possible to do a select on a model using a join and return the model with eagerly loarole 'postgres' does not existHi, Trying to run db:push with a postgres db, gettign this error: ```No config path provided, usingHow would I get 2 unique values?I got my post likes table. ```ts export const postLike = sqliteTable( "post_like", { postId:Infinite scroll w/ Drizzle + tRPCHas anyone implemented infinite scrolling/pagination using Drizzle? The example in the tRPC docs useHRANA_WEBSOCKET_ERROR: Unexpected server response: 404```ts // ./drizzle.config.ts import type { Config } from "drizzle-kit"; export default { schema: URL_INVALIDThe env variables are defined when using `bun run push` but not when using `npm run push` or `pnpm rCustom Logging: hide notice messages ?Hi, I'm using Drizzle ORM with Postgres SQL. Every time I start my project, it does a migration andSpecifying single schema to pushHello: I'm hoping to push a single schema to the database after dropping the table. This way I can`sql.join` with `ODER BY` leads to syntax error while the sql query seems correct.I am conditionally sorting the results from a database query ```ts const sortSqlChunks: SQL[] = []; How to run migration script?I am looking into this doc (https://orm.drizzle.team/kit-docs/overview#running-migrations) regardingCannot get id field in the next-auth session.I am currently working on the drizzle nextjs project. I am using neondb postgresql as database. I amHow to express "children" or "parent" relation with typescript?Let's say I have a `country` and `region` tables. A region belongs to a country, so on the `region`t'token' used in key specification without a key lengthApparently I need to use `token: varchar("token", { length: 255 })` because `token: text("token")`ER_TABLE_EXISTS_ERRORCan someone explain me what is the proper workflow? 1. change schema.ts (add another column to tablcolumn "summary" cannot be cast automatically to type jsonbHello! I'm getting this error when running my migrations, I used to have a text field and now it's how to use in denoim trying to use it in deno but there are errorsPostgres timestamp that will be the same across regionsHello everyone, So I have a statement like the following: ```sql CREATE TABLE your_table_name ( is there a way to wrap a column select with ST_AsText or any other sql statement?I've created a custom column type but the column return by default a binary data, instead i want to inferring the column information from the imported schemais there anyway to get the column information from the imported schema information. When I dump the