DHDistant Horizons
Created by Loser on 3/18/2024 in #help-me
ReTerraForged.
i have spent the last few hours learning about the mystery that is reterraforged, the large gatekeeping community surrounding this mod (which i find to be very complexing) has made it extremally difficult to uncover information. regardless, i have tried to compile it myself starting from absolutely zero coding knowledge, i can not seem to get it to work. Does anyone have a simple jar file for 1.20.1 they could send my way, i would be very grateful.
42 replies
DTDrizzle Team
Created by kinsyu on 12/1/2023 in #help
There's not enough information to infer relation
I am trying to use drizzle studio but I'm running into the following issue, There is not enough information to infer relation "__public__.collectionsTable.tokens". Here's a simplified version of the schema.
export const tokensTable = mysqlTable(
'tokens',
{
tokenId: varchar('token_id', { length: 255 }).notNull(),

metadataName: varchar('metadata_name', { length: 255 }),
metadataDescription: text('metadata_description'),
collectionId: varbinary('collection_id', {
length: 42,
}).notNull(),

createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Token = InferSelectModel<typeof tokensTable>
export type TokenInsert = InferInsertModel<typeof tokensTable>

export const tokensRelations = relations(tokensTable, ({ one }) => ({
collection: one(collectionsTable, {
fields: [tokensTable.collectionId],
references: [collectionsTable.id],
}),
}))

export const collectionsTable = mysqlTable(
'collections',
{
id: varbinary('id', {
length: 42,
}).primaryKey(),

name: varchar('name', {
length: 255,
}).notNull(),
description: text('description'),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Collection = InferSelectModel<typeof collectionsTable>
export type CollectionInsert = InferInsertModel<typeof collectionsTable>

export const collectionsRelations = relations(collectionsTable, ({ one, many }) => ({
tokens: many(tokensTable, {
relationName: 'collectionTokens',
}),
}))
export const tokensTable = mysqlTable(
'tokens',
{
tokenId: varchar('token_id', { length: 255 }).notNull(),

metadataName: varchar('metadata_name', { length: 255 }),
metadataDescription: text('metadata_description'),
collectionId: varbinary('collection_id', {
length: 42,
}).notNull(),

createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Token = InferSelectModel<typeof tokensTable>
export type TokenInsert = InferInsertModel<typeof tokensTable>

export const tokensRelations = relations(tokensTable, ({ one }) => ({
collection: one(collectionsTable, {
fields: [tokensTable.collectionId],
references: [collectionsTable.id],
}),
}))

export const collectionsTable = mysqlTable(
'collections',
{
id: varbinary('id', {
length: 42,
}).primaryKey(),

name: varchar('name', {
length: 255,
}).notNull(),
description: text('description'),
createdAt: timestamp('created_at', {
mode: 'string',
}).defaultNow(),
updatedAt: timestamp('updated_at', {
mode: 'string',
}).defaultNow(),
}
)

export type Collection = InferSelectModel<typeof collectionsTable>
export type CollectionInsert = InferInsertModel<typeof collectionsTable>

export const collectionsRelations = relations(collectionsTable, ({ one, many }) => ({
tokens: many(tokensTable, {
relationName: 'collectionTokens',
}),
}))
In short, each collection can have multiple tokens, but each token can belong to only one collection. I haven't had any issues with this schema for around the 6 months that we've been using it, but we wanted to try out drizzle studio and ran into that issue. The database is running on Planetscale, not sure if that's relevant.
3 replies
DTDrizzle Team
Created by McLean 25 on 4/5/2023 in #help
Can't find meta/_journal.json file when running migrate
3 replies
DTDrizzle Team
Created by iqrow on 5/24/2023 in #help
How to delete with cascade?
I'm using postgres with the following schema (reduced to the important parts):
export const worlds = pgTable('worlds', {
id: uuid('id').defaultRandom().primaryKey()
})
export const users_to_worlds = pgTable(
'users_to_worlds',
{
userId: varchar('user_id', { length: 32 })
.references(() => users.id)
.notNull(),
worldId: uuid('world_id')
.references(() => worlds.id)
.notNull(),
},
(table) => {
return {
pk: primaryKey(table.userId, table.worldId),
}
}
)
export const worlds = pgTable('worlds', {
id: uuid('id').defaultRandom().primaryKey()
})
export const users_to_worlds = pgTable(
'users_to_worlds',
{
userId: varchar('user_id', { length: 32 })
.references(() => users.id)
.notNull(),
worldId: uuid('world_id')
.references(() => worlds.id)
.notNull(),
},
(table) => {
return {
pk: primaryKey(table.userId, table.worldId),
}
}
)
And I'm trying to implement an api call to delete a world. Due to the reference to the world in the users_to_worlds I get the error: Error: update or delete on table "worlds" violates foreign key constraint "users_to_worlds_world_id_worlds_id_fk" on table "users_to_worlds" I believe what I want to use is a CASCADE delete where everything referencing a world is deleted when I delete a world. Is this possible through Drizzle? I can't seem to find anything on this.
7 replies
VVALORANT
Created by Mevix on 1/26/2024 in #community-help
secure boot verification failure
No description
219 replies
DTDrizzle Team
Created by eatmoose on 6/2/2023 in #help
Auto update timestamp fields
How to auto update fields like updated_at?
17 replies
VVALORANT
Created by M. Verstappen! ϟ on 2/15/2024 in #community-help
login servers are temporarily unavaible
No description
23 replies
DTDrizzle Team
Created by Louistiti on 7/18/2023 in #help
Clear the whole database?
For my test environment I'd like to clear the whole db.. is there a way to achieve this using drizzle ?
59 replies
VVALORANT
Created by ᲼᲼J on 2/24/2024 in #community-help
geforce nto detecting
No description
7 replies
DTDrizzle Team
Created by Hocus on 12/5/2023 in #help
Updated drizzle-kit -> Error: Cannot find module 'drizzle-orm/pg-core'
I updated drizzle from:
"drizzle-orm": "^0.29.1",
"drizzle-kit": "^0.20.6",
"drizzle-orm": "^0.29.1",
"drizzle-kit": "^0.20.6",
to
"drizzle-orm": "^0.28.5",
"drizzle-kit": "^0.19.3",
"drizzle-orm": "^0.28.5",
"drizzle-kit": "^0.19.3",
I updated my config to use the new defineConfig method and changed the connectionString to uri
export default defineConfig({
schema: "./src/server/db/schema.ts",
driver: "mysql2",
dbCredentials: {
uri: env.DATABASE_URL,
},
tablesFilter: ["bun-loconta_*"],
});
export default defineConfig({
schema: "./src/server/db/schema.ts",
driver: "mysql2",
dbCredentials: {
uri: env.DATABASE_URL,
},
tablesFilter: ["bun-loconta_*"],
});
but now I am getting this error when I try to run drizzle-kit: Error: Cannot find module 'drizzle-orm/pg-core' I dont use postgres, my driver is mysql2 using PlanetScale as DB provider. my package.json - I am using bun run incase it matters:
"scripts": {
"db:push": "dotenv drizzle-kit push:mysql",
"db:studio": "dotenv drizzle-kit studio",
},
"scripts": {
"db:push": "dotenv drizzle-kit push:mysql",
"db:studio": "dotenv drizzle-kit studio",
},
7 replies
VVALORANT
Created by derek on 12/16/2023 in #community-help
how do you check what you got banned for?
Help
15 replies
PMPUBG MOBILE
Created by Deepblue on 2/2/2024 in #questions
Login failed. Please try again. (211, -541)j
Hello, i am getting this error while trying to login with phone number. Login failed. Please try again. (211, -541) I've tried to login on different devices getting same error. I've changed pw aswell but still same problem. Any idea? Thanks.
2 replies
DTDrizzle Team
Created by fasm on 5/31/2023 in #help
update multiple rows
How can I update values in multiple rows at once?
28 replies
DTDrizzle Team
Created by rushil1o1 on 8/17/2023 in #help
updatedAt timestamp update on DB row update
Whats the best way to update Postgres values for updatedAt --- I'm assuming there's a drizzle helper ? Can't find anything
2 replies
DTDrizzle Team
Created by pablo on 9/21/2023 in #help
Does Drizzle support Microsoft SQL Server?
Does Drizzle support Microsoft SQL Server ?
3 replies
DTDrizzle Team
Created by ippo on 9/15/2023 in #help
TRIGGERS in Drizzle
Is there a way to define/implement TRIGGERs in Drizzle? An example would be great!
13 replies
FFilament
Created by GeRaged | Niklas on 8/29/2023 in #❓┊help
Filament\FilamentManager::getUserName(): Return value must be of type string, null returned
Is it possible to edit the user at Filament? I want instead of the name column, the columns firstname and lastname, but then comes the following error. How can I use my own columns without destroying the logic of filament Filament\FilamentManager::getUserName(): Return value must be of type string, null returned
2 replies
DTDrizzle Team
Created by johnnydt on 7/12/2023 in #help
testing best practices
Can anyone share how they're writing tests that involve drizzle? Looking for something similar to these docs for Prisma: https://www.prisma.io/docs/guides/testing/unit-testing
9 replies
DHDistant Horizons
Created by Puttato on 3/3/2024 in #help-me
How to do the Iris + DH thing
8 replies
DTDrizzle Team
Created by paaradiso on 11/8/2023 in #help
Cannot read properties of undefined (reading 'referencedTable')
i'm just playing around with queries and i can't get this to work:
const liked = await db.query.collectionsTable.findMany({
with: {
likedCollectionsTable: true
}
});
const liked = await db.query.collectionsTable.findMany({
with: {
likedCollectionsTable: true
}
});
without the with it works. i'm passing the schemas to the db object:
export const db = drizzle(queryClient, { schema });
export const db = drizzle(queryClient, { schema });
and here are the two schemas:
export const likedCollectionsTable = pgTable('liked_collections', {
userId: text('user_id').references(() => usersTable.id),
collection_id: integer('collection_id').references(() => collectionsTable.id)
});

export const collectionsTable = pgTable('collections', {
id: integer('id').primaryKey(),
name: text('name'),
type: collectionTypeEnum('type'),
cover: text('cover'),
artist: text('artist'),
tags: text('tags')
.references(() => tagsTable.name)
.array(),
releaseDate: date('release_date'),
addedBy: text('added_by')
});
export const likedCollectionsTable = pgTable('liked_collections', {
userId: text('user_id').references(() => usersTable.id),
collection_id: integer('collection_id').references(() => collectionsTable.id)
});

export const collectionsTable = pgTable('collections', {
id: integer('id').primaryKey(),
name: text('name'),
type: collectionTypeEnum('type'),
cover: text('cover'),
artist: text('artist'),
tags: text('tags')
.references(() => tagsTable.name)
.array(),
releaseDate: date('release_date'),
addedBy: text('added_by')
});
12 replies
DTDrizzle Team
Created by forehead4886 on 9/22/2023 in #help
TypeError: Seems like the schema generic is missing - did you forget to add it to your DB type?
How can I solve the following generic error relating to the db.query.users in my code below?
Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> | { [x: string]:RelationalQueryBuilder<ExtractTablesWithRelations<any>, { ...; }>; }'.

Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.ts(2339)
Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> | { [x: string]:RelationalQueryBuilder<ExtractTablesWithRelations<any>, { ...; }>; }'.

Property 'users' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'.ts(2339)
I'm trying to create an adapter that accepts a generic schema to instantiate a PostgresJsDatabase instance, or colloquially db. I've created the schema that is needed for this adapter, but how can I satisfy typescript when running db.query.user.findFirst()?
import { PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
import { Sql } from "postgres";
import * as schema from "./schema";
import { eq } from "drizzle-orm";

export function postgresAdapter<T extends typeof schema = any>(
sql: Sql,
schema: T
) {
const db = drizzle(sql, { schema });

const { users } = schema;

// This function works below
async function insertUser(
user: typeof users.$inferInsert
): Promise<void> {
await db
.insert(users)
.values(user)
.onConflictDoNothing({ target: users.id });
}

// I'm getting an error here at db.query
async function getUserById(
id: string
): Promise<typeof schema.users.$inferSelect | null> {
const user = await db.query.users.findFirst({
^ // Property 'users' does
// not exist on type
where: (users: any, { eq }) => eq(users.id, id),
});
return user || null;
}
}
import { PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
import { Sql } from "postgres";
import * as schema from "./schema";
import { eq } from "drizzle-orm";

export function postgresAdapter<T extends typeof schema = any>(
sql: Sql,
schema: T
) {
const db = drizzle(sql, { schema });

const { users } = schema;

// This function works below
async function insertUser(
user: typeof users.$inferInsert
): Promise<void> {
await db
.insert(users)
.values(user)
.onConflictDoNothing({ target: users.id });
}

// I'm getting an error here at db.query
async function getUserById(
id: string
): Promise<typeof schema.users.$inferSelect | null> {
const user = await db.query.users.findFirst({
^ // Property 'users' does
// not exist on type
where: (users: any, { eq }) => eq(users.id, id),
});
return user || null;
}
}
5 replies
DTDrizzle Team
Created by Hussein on 10/26/2023 in #help
"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
19 replies
DTDrizzle Team
Created by cvr on 7/4/2023 in #help
How to set a default timestamp_ms for sqlite
How do I make a default timestamp_ms?
createdAt: integer("createdAt", {
mode: "timestamp_ms",
})
.notNull().default( // what goes in here )
createdAt: integer("createdAt", {
mode: "timestamp_ms",
})
.notNull().default( // what goes in here )
16 replies
DTDrizzle Team
Created by { ken } on 6/26/2023 in #help
Auto update for updated_at
Any thoughts on how I could implement an auto updated field triggered on updates only on Postgres? I see onUpdateNow() for MySql. Seems Postgres supports triggers for this. Can/should I use Postgres triggers via Drizzle? If not, does it make sense to send the updated_at over the wire from the client?
14 replies