postgres
This commit is contained in:
parent
b0f3e6c576
commit
e44d419b58
15 changed files with 233 additions and 82 deletions
|
@ -1,16 +1,35 @@
|
|||
"use server";
|
||||
import { initConnection } from "@/components/db-utils";
|
||||
import { initConnectionPostgres, initConnectionSurreal } from "@/components/db-utils";
|
||||
|
||||
export async function querydb(slug: string) {
|
||||
let long_url = undefined;
|
||||
try {
|
||||
let db = await initConnection();
|
||||
let long_url = await db.query(`
|
||||
update url:[$id] set clicks = clicks + 1 ;
|
||||
select * from url:[$id];
|
||||
`, { id: slug });
|
||||
if (process.env.DB_TYPE === "surrealdb") {
|
||||
|
||||
// @ts-ignore
|
||||
long_url = long_url[0][0].long_url;
|
||||
let db = await initConnectionSurreal();
|
||||
let long_url = await db.query(`
|
||||
update url:[$id]
|
||||
set clicks = clicks + 1;
|
||||
select * from url:[$id];
|
||||
`, { id: slug });
|
||||
|
||||
// @ts-ignore
|
||||
long_url = long_url[0][0].long_url;
|
||||
}
|
||||
|
||||
if (process.env.DB_TYPE === "postgres") {
|
||||
let sql = await initConnectionPostgres();
|
||||
long_url = await sql`
|
||||
update url set
|
||||
clicks = clicks + 1,
|
||||
date_accessed = now()
|
||||
where id = ${slug}
|
||||
returning long_url;
|
||||
`;
|
||||
long_url = long_url[0].long_url;
|
||||
}
|
||||
|
||||
console.log(long_url);
|
||||
return long_url;
|
||||
} catch (e) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue