ultrakiller
ultrakiller
Explore posts from servers
DTDrizzle Team
Created by ultrakiller on 8/12/2023 in #help
How am I supposed to put unique constraints on columns
13 replies
DTDrizzle Team
Created by ultrakiller on 8/9/2023 in #help
Infinite loading of queries
Hey! I am trying to use Drizzle with Neon Postgres. I made the migrations, ran them and the tables are there. Now whenever I select or insert data, the request just hangs and does not proceed. I am using serverless neon package since I will be running in Vercel Edge Functions. Here is the code:
import {drizzle} from "drizzle-orm/neon-serverless";
import {Pool} from '@neondatabase/serverless';
import {Orders} from "@/app/db/schema";
import {eq} from "drizzle-orm";

export interface Order {
instagram_post_id: string
}

const client = new Pool({
connectionString: process.env.DATABASE_CONNECTION_STRING,
ssl: true,
idleTimeoutMillis: 20000,
})
const db = drizzle(client)

export const getOrder = async (id: string) => {
return db.select().from(Orders).where(eq(Orders.instagram_post_id, id));
}
export const addOrder = async (order: Order) => {
try {
const orderReq = await db.insert(Orders).values({
instagram_post_id: order.instagram_post_id,
}).returning()
console.log({orderReq})
} catch (e) {
console.log({e})
}
return order
}
import {drizzle} from "drizzle-orm/neon-serverless";
import {Pool} from '@neondatabase/serverless';
import {Orders} from "@/app/db/schema";
import {eq} from "drizzle-orm";

export interface Order {
instagram_post_id: string
}

const client = new Pool({
connectionString: process.env.DATABASE_CONNECTION_STRING,
ssl: true,
idleTimeoutMillis: 20000,
})
const db = drizzle(client)

export const getOrder = async (id: string) => {
return db.select().from(Orders).where(eq(Orders.instagram_post_id, id));
}
export const addOrder = async (order: Order) => {
try {
const orderReq = await db.insert(Orders).values({
instagram_post_id: order.instagram_post_id,
}).returning()
console.log({orderReq})
} catch (e) {
console.log({e})
}
return order
}
route.ts
import {NextResponse} from 'next/server'
import {addOrder, getOrder} from "@/lib/drizzle";

export async function POST(req: Request) {
const data = await req.json()
console.log({data})
const addRequest = await addOrder(data)
console.log({addRequest})
return NextResponse.json({addRequest})
}

export async function GET(req: Request) {
console.log("Request Made")
const {searchParams} = new URL(req.url)
const id = searchParams.get('id') ?? ""
const getReq = await getOrder(id)
console.log({getReq})
return NextResponse.json({getReq})
}
import {NextResponse} from 'next/server'
import {addOrder, getOrder} from "@/lib/drizzle";

export async function POST(req: Request) {
const data = await req.json()
console.log({data})
const addRequest = await addOrder(data)
console.log({addRequest})
return NextResponse.json({addRequest})
}

export async function GET(req: Request) {
console.log("Request Made")
const {searchParams} = new URL(req.url)
const id = searchParams.get('id') ?? ""
const getReq = await getOrder(id)
console.log({getReq})
return NextResponse.json({getReq})
}
8 replies