Prisma : table create
📘 Prisma তে টেবিল তৈরি করার Basic Syntax (Model Definition):
model ModelName {
fieldName1 FieldType @attribute
fieldName2 FieldType @attribute
}
👉 এখানে model
= table
👉 fieldName
= column name
👉 FieldType
= data type
👉 @attribute
= constraint বা instruction (যেমন primary key, unique)
🧾 উদাহরণ: (Raw SQL vs Prisma)
🔹 Raw SQL:
CREATE TABLE User (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE
);
🔸 Prisma:
model User {
id Int @id @default(autoincrement())
name String
email String @unique
}
🔤 Prisma এর Common Data Types:
Prisma Type | Description | Maps To (MySQL) |
---|---|---|
Int |
পূর্ণ সংখ্যা | INT |
String |
টেক্সট | VARCHAR |
Boolean |
সত্য/মিথ্যা | BOOLEAN |
DateTime |
সময় | DATETIME |
Float |
ভগ্নাংশ সংখ্যা | FLOAT |
Decimal |
নির্ভুল ভগ্নাংশ | DECIMAL |
Json |
JSON ডেটা | JSON |
@id |
Primary Key | — |
@default() |
Default value | — |
@unique |
Unique constraint | — |
@relation |
Foreign Key রিলেশন | — |
🎯 আরও একটি উদাহরণ:
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
createdAt DateTime @default(now())
}
ব্যাখ্যা:
id
= primary key, auto increment-
title
= string, required -
content
= optional string (?
দিয়ে optional বোঝানো হয়) -
published
= boolean, ডিফল্ট false -
createdAt
= datetime, ডিফল্ট এখনকার সময়
🔚 সংক্ষেপে:
Prisma তে টেবিল তৈরি করতে
model
ব্যবহার করা হয়, যেখানে প্রতিটি ফিল্ড এর type ও constraint define করা হয়। SQL এর তুলনায় অনেক clean, readable ও টাইপ-সেইফ।