Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Druue committed Apr 30, 2024
1 parent 8f777db commit 00987d5
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 22 deletions.
41 changes: 35 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { Prisma, PrismaClient } from "@prisma/client";
import { Prisma, PrismaClient, BaseUser } from "@prisma/client";
import { validate } from "@prisma/prisma-schema-wasm";
import { loadSchemaFiles } from "@prisma/schema-files-loader";

import { Pool } from "pg";
import { PrismaPg } from "@prisma/adapter-pg";

const connectionString = `${process.env.DATABASE_URL}`;

const pool = new Pool({ connectionString });
const adapter = new PrismaPg(pool);
const prisma = new PrismaClient({
adapter,
log: ["query"],
});

// const prisma = new PrismaClient({
// log: ["query"],
// });

// you can do stuff in the client constructor
// const prisma = new PrismaClient({
// __internal: { enginePath: '/prisma-engines/target/debug/query-engine' }
Expand All @@ -14,23 +26,40 @@ const prisma = new PrismaClient({
// you can do middlewares on
// prisma.$use

const id = "123e4567-e89b-12d3-a456-426655440000";

const populate = async () => {
await prisma.a.create({
await prisma.baseUser.create({
data: {
id: 0,
id,
intId: 1,
},
});
};

const getUnsafe = async (id: bigint): Promise<BaseUser | null> => {
const query = {
where: { intId: id },
// include: { user: true },
};

const result = await prisma.baseUser.findUnique(query);
if (!result) {
return null;
}

return result;
};

async function test() {
const a = await prisma.a.findFirst();
console.log(a);
const u = getUnsafe(BigInt(1));
console.log(u);
}

async function main() {
// console.log(process.env.DATABASE_URL);

// await populate();
await populate();
return test();

// const prismaSchema = await loadSchemaFiles("./prisma/schema");
Expand Down
Loading

0 comments on commit 00987d5

Please sign in to comment.