Init the prisma starter profile for cubetiq team and add some functions for migration and playaround

This commit is contained in:
2021-03-13 10:10:40 +07:00
commit fc7d91e98a
10 changed files with 154 additions and 0 deletions

51
src/main.ts Normal file
View File

@@ -0,0 +1,51 @@
import { PrismaClient, User } from "@prisma/client";
const prisma = new PrismaClient();
// A `main` function so that you can use async/await
async function main() {
// create user
await createUser()
.then((user) => {
// create profile for user
createProfile(user);
})
.catch((e) => {
console.error(e);
});
const allUsers = await prisma.user.findMany();
console.log("All users => ", allUsers);
}
async function createUser() {
const user = await prisma.user.create({
data: {
name: "CUBETIQ Solution",
email: "ops@cubetiqs.com",
},
});
console.log("User => ", user);
return user;
}
async function createProfile(user: User) {
const profile = await prisma.profile.create({
data: {
userId: user.id,
bio: "Software Company",
},
});
console.log("Profile => ", profile);
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
});