Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Druue committed May 14, 2024
1 parent 8f777db commit 90dfe3f
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 81 deletions.
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
# DATABASE_URL="postgres://postgres:prisma@localhost:5432/postgres"
# DATABASE_URL="postgres://postgres:prisma@localhost:5433/postgres"
# DATABASE_URL="postgres://postgres:prisma@localhost:5434/postgres"
DATABASE_URL="postgres://postgres:prisma@localhost:5435/postgres"
# DATABASE_URL="postgres://postgres:prisma@localhost:5435/postgres"

#MySQL 5.6, 5.7, 8.0, Maria 10.0
# DATABASE_URL="mysql://root:prisma@localhost:3309/prisma"
# DATABASE_URL="mysql://root:prisma@localhost:3306/prisma"
# DATABASE_URL="mysql://root:prisma@localhost:3307/prisma"
# DATABASE_URL="mysql://root:prisma@localhost:3308/prisma"

#MSSql 2017, 2019
# DATABASE_URL="sqlserver://localhost:1433;database=master;user=SA;password=<YourStrong@Passw0rd>;trustServerCertificate=true"
#MSSql 2017 (edge), 2019
DATABASE_URL="sqlserver://localhost:1433;database=master;user=SA;password=<YourStrong@Passw0rd>;trustServerCertificate=true"
# DATABASE_URL="sqlserver://localhost:1434;database=master;user=SA;password=<YourStrong@Passw0rd>;trustServerCertificate=true"

#SQLite
Expand Down
37 changes: 30 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { validate } from "@prisma/prisma-schema-wasm";
import { loadSchemaFiles } from "@prisma/schema-files-loader";

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

// you can do stuff in the client constructor
Expand All @@ -15,22 +15,45 @@ const prisma = new PrismaClient({
// prisma.$use

const populate = async () => {
await prisma.a.create({
const { id } = await prisma.user.create({
data: {
id: 0,
},
posts: {
createMany: {
data: Array(4000).fill({ title: 'post' }),
}
}
}
});
};

async function test() {
const a = await prisma.a.findFirst();
console.log(a);
// ! this doesn't work
// const r = await prisma.post.findMany({
// where: { authorId: { in: Array.from(Array(4000).keys()) } },
// select: { id: true, title: true },
// orderBy: { createdAt: 'asc' },
// });

// * this works
const r = await prisma.post.findMany({
where: { authorId: { in: Array.from(Array(4000).keys()) } },
select: { id: true, title: true, createdAt: true },
orderBy: { createdAt: 'asc' },
});

console.log(r);

// * this works too
// await prisma.post.findMany({
// where: { authorId: { in: Array.from(Array(4000).keys()) } },
// orderBy: { createdAt: 'asc' },
// });
}

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

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

// const prismaSchema = await loadSchemaFiles("./prisma/schema");
Expand Down
124 changes: 62 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"devDependencies": {
"@prisma/prisma-schema-wasm": "5.13.0-7.87bc6b811aafa9b7bcdb787a2b8c8b5728cbbfb0",
"@prisma/schema-files-loader": "5.13.0-dev.33",
"prisma": "^5.13.0",
"prisma": "^5.14.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
},
"dependencies": {
"@prisma/client": "^5.13.0",
"@prisma/client": "^5.14.0",
"dotenv": "^16.0.3"
}
}
}
16 changes: 10 additions & 6 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ generator client {
}

datasource db {
provider = "postgresql"
provider = "sqlserver"
url = env("DATABASE_URL")
}

model A {
id Int @id
model User {
id Int @id @default(autoincrement())
posts Post[]
}

model B {
id Int @id
field String
model Post {
id Int @id @default(autoincrement())
title String
author User @relation(fields: [authorId], references: [id])
authorId Int
createdAt DateTime @default(now())
}

0 comments on commit 90dfe3f

Please sign in to comment.