Anand
Anand
Explore posts from servers
TtRPC
Created by Anand on 9/25/2024 in #❓-help
what will happen if we do not wrap the client component with hydrate client?
https://trpc.io/docs/client/react/server-components#utilizing-your-api
import { trpc } from '~/trpc/server';
import { ClientGreeting } from './client-greeting';

export default async function Home() {
void trpc.hello.prefetch();

return (
<HydrateClient>
<div>...</div>
{/** ... */}
<ClientGreeting />
</HydrateClient>
);
}
import { trpc } from '~/trpc/server';
import { ClientGreeting } from './client-greeting';

export default async function Home() {
void trpc.hello.prefetch();

return (
<HydrateClient>
<div>...</div>
{/** ... */}
<ClientGreeting />
</HydrateClient>
);
}
because I did not and my app works just fine, moreover I even removed the prefetch, yet all the client component (using useSuspenseQuery) worked fine and do not fetch on client (till after stale time). I was just wondering what is the use case of prefetch() an HydrateClient
3 replies
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
No description
8 replies
RRailway
Created by Anand on 9/2/2023 in #✋|help
Unused Database
Hey, I have a backend talking to my express server. Both are hosted on Railway. The thing is I am not using the database all the time. What should I do? Will I be charged for the DB all around the month? Is DB not based on usage?
28 replies
DTDrizzle Team
Created by Anand on 8/22/2023 in #help
Connection to SQL destroyed (after idle). Do I need to manually handle open + close for each query?
i deployed my SQL server and nodejs server on railway. The server is up and running, for some reason my SQL connection disconnected? I was wondering if I am missing something fundamental or what?
database.ts
import dotenv from "dotenv";
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

import * as schema from "../schema.js";

dotenv.config();

const connection = await mysql.createConnection({
host: process.env.MYSQLHOST,
port: Number(process.env.MYSQLPORT),
user: process.env.MYSQLUSER,
password: process.env.MYSQLPASSWORD,
database: process.env.MYSQLDATABASE,
});

const db = drizzle(connection, { schema, mode: "default" });

export { db };
database.ts
import dotenv from "dotenv";
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";

import * as schema from "../schema.js";

dotenv.config();

const connection = await mysql.createConnection({
host: process.env.MYSQLHOST,
port: Number(process.env.MYSQLPORT),
user: process.env.MYSQLUSER,
password: process.env.MYSQLPASSWORD,
database: process.env.MYSQLDATABASE,
});

const db = drizzle(connection, { schema, mode: "default" });

export { db };
I am using this db in different controllers to make queries. Am i messing up somewhere?
example query
const userTodos = await db.query.users.findFirst({
where: eq(users.id, +userId),
with: {
todos: {
where: (todoItem) => eq(todoItem.type, type),
},
},
});
example query
const userTodos = await db.query.users.findFirst({
where: eq(users.id, +userId),
with: {
todos: {
where: (todoItem) => eq(todoItem.type, type),
},
},
});
Should I handle the open and close state manually in every query or am I missing something?
15 replies