tomeverson
Explore posts from serversDTDrizzle Team
•Created by tomeverson on 9/7/2023 in #help
No transactions support in neon-http driver
Any Workaround on this ?
1 replies
DTDrizzle Team
•Created by tomeverson on 9/4/2023 in #help
Prepared Statement doesn't exist
"message": "db error: ERROR: prepared statement \"s114\" does not exist\n\nCaused by:\n ERROR: prepared statement \"s114\" does not exist"
"message": "db error: ERROR: prepared statement \"s114\" does not exist\n\nCaused by:\n ERROR: prepared statement \"s114\" does not exist"
export const hubVotes = pgTable(
"HubVotes",
{
userId: integer("UserId")
.notNull(),
hubPostId: integer("HubId")
.notNull(),
vote: voteEnum("Vote").notNull(),
},
(t) => ({
pk: primaryKey(t.userId, t.hubPostId),
})
);
export const hubVotes = pgTable(
"HubVotes",
{
userId: integer("UserId")
.notNull(),
hubPostId: integer("HubId")
.notNull(),
vote: voteEnum("Vote").notNull(),
},
(t) => ({
pk: primaryKey(t.userId, t.hubPostId),
})
);
route.patch("/", async (req, res) => {
const vote = req.body as NewHubVote;
console.log(req.userId, vote.hubPostId)
//* Check The Existing Vote
const existingvote = await searchHubVote(req.userId);
if (existingvote) {
//* If the vote are same, remove the votes
if (existingvote.vote === vote.vote) {
await removeHubVote({ userId: req.userId });
res.status(200)
return res.send("OK");
}
await updateHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK");
}
//* If no Vote Existed, Create a New One
await createHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK")
});
}
route.patch("/", async (req, res) => {
const vote = req.body as NewHubVote;
console.log(req.userId, vote.hubPostId)
//* Check The Existing Vote
const existingvote = await searchHubVote(req.userId);
if (existingvote) {
//* If the vote are same, remove the votes
if (existingvote.vote === vote.vote) {
await removeHubVote({ userId: req.userId });
res.status(200)
return res.send("OK");
}
await updateHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK");
}
//* If no Vote Existed, Create a New One
await createHubVote({
userId: req.userId,
hubPostId: vote.hubPostId,
vote: vote.vote,
});
res.status(200)
return res.send("OK")
});
}
5 replies
DTDrizzle Team
•Created by tomeverson on 8/23/2023 in #help
NeonDB: Migration Taking Long
Hi, I have been using dirrzle with neon DB, and it has been a great experience. However, once I changed my schema a lil bit and migrate again, it was taking extremely long time and query is never executed.
db/index.ts
db/migrate.ts
package.json
import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from "@/db/schema";
import "dotenv/config";
// create database connection
neonConfig.fetchConnectionCache = true;
const connection = neon(process.env.DATABASE_URL!);
export const db = drizzle(connection, { schema: schema });
import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from "@/db/schema";
import "dotenv/config";
// create database connection
neonConfig.fetchConnectionCache = true;
const connection = neon(process.env.DATABASE_URL!);
export const db = drizzle(connection, { schema: schema });
import { migrate } from "drizzle-orm/neon-http/migrator";
import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import "dotenv/config";
// inspired by Raphael Moreau @rphlmr for Postgres, extended for Planetscale
const runMigrate = async () => {
if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not defined");
}
neonConfig.fetchConnectionCache = true;
const connection = neon(process.env.DATABASE_URL!);
const db = drizzle(connection);
console.log("⏳ Running migrations...");
const start = Date.now();
await migrate(db, { migrationsFolder: "migrations" });
const end = Date.now();
console.log(`✅ Migrations completed in ${end - start}ms`);
process.exit(0);
};
runMigrate().catch((err) => {
console.error("❌ Migration failed");
console.error(err);
process.exit(1);
});
import { migrate } from "drizzle-orm/neon-http/migrator";
import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import "dotenv/config";
// inspired by Raphael Moreau @rphlmr for Postgres, extended for Planetscale
const runMigrate = async () => {
if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not defined");
}
neonConfig.fetchConnectionCache = true;
const connection = neon(process.env.DATABASE_URL!);
const db = drizzle(connection);
console.log("⏳ Running migrations...");
const start = Date.now();
await migrate(db, { migrationsFolder: "migrations" });
const end = Date.now();
console.log(`✅ Migrations completed in ${end - start}ms`);
process.exit(0);
};
runMigrate().catch((err) => {
console.error("❌ Migration failed");
console.error(err);
process.exit(1);
});
"scripts": {
"start": "tsx --watch src/index.ts",
"test": "tsx src/test.ts",
"db:migrate": "drizzle-kit generate:pg",
"db:studio": "drizzle-kit studio",
"db:push": "tsx db/migrate.ts",
"db:drop": "drizzle-kit drop --config=drizzle.config.ts"
}
"scripts": {
"start": "tsx --watch src/index.ts",
"test": "tsx src/test.ts",
"db:migrate": "drizzle-kit generate:pg",
"db:studio": "drizzle-kit studio",
"db:push": "tsx db/migrate.ts",
"db:drop": "drizzle-kit drop --config=drizzle.config.ts"
}
5 replies
DTDrizzle Team
•Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
export const hubPost = pgTable("HubPost", {
id: uuid("Id").defaultRandom().primaryKey(),
text: text("Text").notNull(),
title: varchar("Title", { length: 256 }).notNull(),
hub: varchar("Hub", { length: 128 }).notNull(),
authorId: uuid("AuthorId").notNull(),
});
export const hub = pgTable("Hub", {
id: uuid("Id").defaultRandom().primaryKey(),
name: varchar("Name", { length: 128 }).notNull(),
createdAt: timestamp("CreatedAt").defaultNow(),
creatorId: varchar("CreatorId").notNull(),
});
export const hubRelationsToHubPost = relations(hub, ({ many }) => ({
hubPosts: many(hubPost),
}));
export const hubPostRelationsToHub = relations(hubPost, ({ one }) => ({
hub: one(hub, {
fields: [hubPost.hub],
references: [hub.id],
}),
}));
export const hubPost = pgTable("HubPost", {
id: uuid("Id").defaultRandom().primaryKey(),
text: text("Text").notNull(),
title: varchar("Title", { length: 256 }).notNull(),
hub: varchar("Hub", { length: 128 }).notNull(),
authorId: uuid("AuthorId").notNull(),
});
export const hub = pgTable("Hub", {
id: uuid("Id").defaultRandom().primaryKey(),
name: varchar("Name", { length: 128 }).notNull(),
createdAt: timestamp("CreatedAt").defaultNow(),
creatorId: varchar("CreatorId").notNull(),
});
export const hubRelationsToHubPost = relations(hub, ({ many }) => ({
hubPosts: many(hubPost),
}));
export const hubPostRelationsToHub = relations(hubPost, ({ one }) => ({
hub: one(hub, {
fields: [hubPost.hub],
references: [hub.id],
}),
}));
19 replies