Anand
Anand
Explore posts from servers
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
@Andrew Sherman
8 replies
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
No description
8 replies
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
I am able to generate SQL file, but not able to migrate or connect to it
8 replies
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
I am currently in the web app of my turborepo (the web app is a single nextjs app router app)
8 replies
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
No description
8 replies
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
drizzle.config.ts
import type { Config } from "drizzle-kit";

const PGUSER = decodeURIComponent(process.env.PGUSER || "");

export default {
schema: "./db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
host: process.env.PGHOST || "",
user: PGUSER,
password: process.env.PGPASSWORD || "",
database: process.env.PGDATABASE || "",
port: 5432,
ssl: true,
},
} satisfies Config;
import type { Config } from "drizzle-kit";

const PGUSER = decodeURIComponent(process.env.PGUSER || "");

export default {
schema: "./db/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
host: process.env.PGHOST || "",
user: PGUSER,
password: process.env.PGPASSWORD || "",
database: process.env.PGDATABASE || "",
port: 5432,
ssl: true,
},
} satisfies Config;
8 replies
DTDrizzle Team
Created by Anand on 11/3/2023 in #help
Postgresjs with Neon giving connnection refusal error
index.ts this file contains the drizzle connection logic
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

const PGUSER = decodeURIComponent(process.env.PGUSER || "");

const queryClient = postgres({
host: process.env.PGHOST || "",
user: PGUSER,
password: process.env.PGPASSWORD || "",
database: process.env.PGDATABASE || "",
port: 5432,
ssl: true,
});
const db = drizzle(queryClient);

export default db;
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";

const PGUSER = decodeURIComponent(process.env.PGUSER || "");

const queryClient = postgres({
host: process.env.PGHOST || "",
user: PGUSER,
password: process.env.PGPASSWORD || "",
database: process.env.PGDATABASE || "",
port: 5432,
ssl: true,
});
const db = drizzle(queryClient);

export default db;
8 replies
DTDrizzle Team
Created by roob on 8/7/2023 in #help
Do I need to close the DB connection after running a script using drizzle?
yup it works. you are right. what I found werid was why the single connection was not behaving in the same way...
25 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?
this makes sense. thanks alot Andrew.
15 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?
that is maybe because my DB did not receive any request for 8 hrs or more and hence the connection was closed.
15 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?
the error I am currently getting is Can't add new command when connection is in closed state
15 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?
Ok i will try the pool way.
15 replies
DTDrizzle Team
Created by roob on 8/7/2023 in #help
Do I need to close the DB connection after running a script using drizzle?
the error I am getting is Can't add new command when connection is in closed state which basically means my connectionto sql db is closed and thus I cannot access it.
25 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?
so I should create a pool of connections and pass it to drizzle(poolConnection, otherConfigs) and then i will simply use the db for querying right?
15 replies
DTDrizzle Team
Created by roob on 8/7/2023 in #help
Do I need to close the DB connection after running a script using drizzle?
so it is quite possible that the there are no requests for days, and then all of a sudden recruiters try their hand on my app
25 replies
DTDrizzle Team
Created by roob on 8/7/2023 in #help
Do I need to close the DB connection after running a script using drizzle?
this is a side project with hardly any users
25 replies
DTDrizzle Team
Created by roob on 8/7/2023 in #help
Do I need to close the DB connection after running a script using drizzle?
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 places 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),
},
},
});
25 replies
DTDrizzle Team
Created by roob on 8/7/2023 in #help
Do I need to close the DB connection after running a script using drizzle?
i am facing a similar issue in mysql DB. should I close my connection after each query? how does that work? there is no clear doc around this..
25 replies