adding gorm

This commit is contained in:
2025-11-17 22:26:21 +00:00
parent ff32c4fa8e
commit fee7e26336
4 changed files with 64 additions and 1 deletions

11
backend/models/post.go Normal file
View File

@@ -0,0 +1,11 @@
package models
import "gorm.io/gorm"
type Post struct {
gorm.Model // includes ID, CreatedAt, UpdatedAt, DeletedAt
Title string `gorm:"not null"`
Content string `gorm:"type:text; not null"`
AuthorID uint // foreign key to User
Author User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` // optional relation
}

10
backend/models/user.go Normal file
View File

@@ -0,0 +1,10 @@
package models
import "gorm.io/gorm"
type User struct {
gorm.Model // includes ID, CreatedAt, UpdatedAt, DeletedAt
Name string
Email string `gorm:"uniqueIndex"`
Password string
}