Eternal Mori
Eternal Mori
Explore posts from servers
DTDrizzle Team
Created by Eternal Mori on 3/16/2024 in #help
drizzle-kit push error: Multiple primary key defined
My database and table in this example are using MariaDB with collation: utf8mb4_general_ci. When I use MySQL with utf8mb4_0900_ai_ci I dont experience this error.
3 replies
TtRPC
Created by nitestack on 8/26/2023 in #❓-help
Next.js app router + TRPC...how to set it up?
See the code from the T3 Turborepo. https://github.com/t3-oss/create-t3-turbo
7 replies
TTCTheo's Typesafe Cult
Created by Eternal Mori on 7/16/2023 in #questions
Handling Long-Running Server Functions in Next.js: Seeking Alternatives to Vercel Time Limits
Thanks @nyx (Rustular DevRel) for your suggestion, I will do my research!
8 replies
TTCTheo's Typesafe Cult
Created by Eternal Mori on 7/16/2023 in #questions
Handling Long-Running Server Functions in Next.js: Seeking Alternatives to Vercel Time Limits
Do you mean sst.dev?
8 replies
DTDrizzle Team
Created by Dustin@WunderGraph on 7/12/2023 in #help
How to do conditional joins with the query builder?
All equels with a undefined value are ignored
18 replies
DTDrizzle Team
Created by Dustin@WunderGraph on 7/12/2023 in #help
How to do conditional joins with the query builder?
Here is a where clause with conditional params:
.where(
and(
channel ? eq(s.tickets.channelId, channel) : undefined,
status ? eq(s.tickets.status, status) : undefined,
eq(s.channels.organizationId, organizationId)
)
)
.where(
and(
channel ? eq(s.tickets.channelId, channel) : undefined,
status ? eq(s.tickets.status, status) : undefined,
eq(s.channels.organizationId, organizationId)
)
)
18 replies
DTDrizzle Team
Created by Eternal Mori on 7/12/2023 in #help
How to implement a where clause on a joined table with the new relation builder?
Now I created almost an indentical output with the new builder. But now the problem is that I dont know how to filter on a joined table. in this example on "ticket.channel.organizationId". That part is missing here. How can I implement the filter?
const ticket = await db.query.tickets.findFirst({
columns: {
id: true,
status: true,
},
with: {
channel: {
columns: {
id: true,
type: true,
name: true,
organizationId: true,
},
},
contact: {
columns: {
id: true,
name: true,
email: true,
},
},
messages: {
columns: {
id: true,
subject: true,
text: true,
html: true,
createdAt: true,
},
},
},
where: (table, { and, eq, sql }) => and(eq(table.id, params.id)),
});
const ticket = await db.query.tickets.findFirst({
columns: {
id: true,
status: true,
},
with: {
channel: {
columns: {
id: true,
type: true,
name: true,
organizationId: true,
},
},
contact: {
columns: {
id: true,
name: true,
email: true,
},
},
messages: {
columns: {
id: true,
subject: true,
text: true,
html: true,
createdAt: true,
},
},
},
where: (table, { and, eq, sql }) => and(eq(table.id, params.id)),
});
4 replies
TTCTheo's Typesafe Cult
Created by Wildhide on 7/11/2023 in #questions
TRPC server side prefetching not working properly
because you added these later?
5 replies
TTCTheo's Typesafe Cult
Created by Wildhide on 7/11/2023 in #questions
TRPC server side prefetching not working properly
Arent the database records corrupt or do the new column createdAt has default values for datetime?
5 replies
TTCTheo's Typesafe Cult
Created by whizzy on 7/10/2023 in #questions
Anyone know how to connect to custom domain?
You can also use a CNAME record like pagwin said, but set it up with a providers API. for example, you can create new domains and set a CNAME record with the vercel API so your users dont have to set it up!
15 replies
TTCTheo's Typesafe Cult
Created by Coded_58 on 7/11/2023 in #questions
Testing and Debugging Next.js13 apps for production
These are the best video's from Theo that gave me answers to these questions: https://www.youtube.com/watch?v=ZGKGb109-I4 https://www.youtube.com/watch?v=FF50H2RWaEY
4 replies
TTCTheo's Typesafe Cult
Created by __equilibrium__ on 7/10/2023 in #questions
HOW TO SELF-HOST UPLOADTHING
Create your own uploadthing backend (yesterday I spoke to Theo, at this moment there just a couple of lambda scripts that handle the requests. it's not finished, there is no "perfect" backend at te moment. but it would be great to give feedback based on your own implementations!
7 replies
TTCTheo's Typesafe Cult
Created by __equilibrium__ on 7/10/2023 in #questions
HOW TO SELF-HOST UPLOADTHING
If you realy want to know you need to dig deep inside the opensource upload thing package en expore how to uploadthing.com server requests are coming in. Then you need to explore how S3 works with it's node API. Then you can create your own API routes that are called from uploadthing, to your own API routes that handles the requests.
7 replies
DTDrizzle Team
Created by Eternal Mori on 7/3/2023 in #help
Broken typescript in select
import { connect } from "@planetscale/database";
import { type DrizzleConfig } from "drizzle-orm";
import { drizzle as mysqlDrizzle } from "drizzle-orm/mysql2";
import { drizzle as planetscaleDrizzle } from "drizzle-orm/planetscale-serverless";
import mysql from "mysql2/promise";

import * as schema from "~/lib/drizzle/schema";
import { env } from "~/env.mjs";

const isDev = env.NODE_ENV === "development";

const mysqlConnection = await mysql.createConnection({
uri: env.DATABASE_URL,
});

const planetscaleConnection = connect({
url: env.DATABASE_URL,
});

const config: DrizzleConfig<typeof schema> = {
schema,
logger: env.NODE_ENV === "development",
};

export const db = isDev
? mysqlDrizzle(mysqlConnection, config)
: planetscaleDrizzle(planetscaleConnection, config);
import { connect } from "@planetscale/database";
import { type DrizzleConfig } from "drizzle-orm";
import { drizzle as mysqlDrizzle } from "drizzle-orm/mysql2";
import { drizzle as planetscaleDrizzle } from "drizzle-orm/planetscale-serverless";
import mysql from "mysql2/promise";

import * as schema from "~/lib/drizzle/schema";
import { env } from "~/env.mjs";

const isDev = env.NODE_ENV === "development";

const mysqlConnection = await mysql.createConnection({
uri: env.DATABASE_URL,
});

const planetscaleConnection = connect({
url: env.DATABASE_URL,
});

const config: DrizzleConfig<typeof schema> = {
schema,
logger: env.NODE_ENV === "development",
};

export const db = isDev
? mysqlDrizzle(mysqlConnection, config)
: planetscaleDrizzle(planetscaleConnection, config);
3 replies
DTDrizzle Team
Created by Eternal Mori on 7/3/2023 in #help
Broken typescript in select
I fixed it, it was because I used a dynamic db connection:
3 replies
DTDrizzle Team
Created by eatmoose on 6/2/2023 in #help
Auto update timestamp fields
Planetscale advices to update these values on app level, because if you use mysql functions like: "NOW()" or "CURRENT_TIMESTAMP()" they will use the mysql server time and timezone. If you want to use the timezone of your own app. set these values at app level. My Schema TS file:
const updatedAndCreatedAt = {
updatedAt: datetime("updatd_at").notNull(),
createdAt: datetime("created_at").notNull(),
};

export const users = table(
"users",
{
id: varchar("id", { length: 36 }).primaryKey(),
...all other fields,
...updatedAndCreatedAt,
}
);
const updatedAndCreatedAt = {
updatedAt: datetime("updatd_at").notNull(),
createdAt: datetime("created_at").notNull(),
};

export const users = table(
"users",
{
id: varchar("id", { length: 36 }).primaryKey(),
...all other fields,
...updatedAndCreatedAt,
}
);
When creating my record:
await db
.insert(schema.users)
.values({
id,
...al other fields,
createdAt: new Date(),
updatedAt: new Date(),
})
.execute();
await db
.insert(schema.users)
.values({
id,
...al other fields,
createdAt: new Date(),
updatedAt: new Date(),
})
.execute();
When updating:
await db
.update(schema.users)
.set({
...body,
updatedAt: new Date(),
})
.execute()
await db
.update(schema.users)
.set({
...body,
updatedAt: new Date(),
})
.execute()
17 replies
TtRPC
Created by Maj on 6/9/2023 in #❓-help
trpc with app dir nextjs
11 replies
TtRPC
Created by PotatisMannen on 6/18/2023 in #❓-help
how does one actually make trpc/client work with the app router
3 replies
TtRPC
Created by Eternal Mori on 4/21/2023 in #❓-help
Can you get the queryClient without using a hook?
I forgot to add that I am using it with NextJS, I have a withTRPC wrapper in my App. Is there a way to extract the queryClient from there?
7 replies