From f63e8475b0dd83febaae2f6e2a967a2be02ec503 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 31 Aug 2025 10:48:14 -0400 Subject: [PATCH] Remove the T4C stuff but have an example of using null. --- data/models.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/data/models.go b/data/models.go index 6fe4e13..021f6c5 100644 --- a/data/models.go +++ b/data/models.go @@ -17,26 +17,17 @@ type User struct { Password string `db:"password" validate:"required,min=8,max=64"` } -type Message struct { +/* + * Example of using the null library to do optional fields. + */ +type NullExample struct { Id int `db:"id" json:"id" validate:"numeric"` - Text string `db:"text" json:"text" validate:"required,max=512"` - UserId int `db:"user_id" json:"user_id" validate:"numeric"` - CreatedAt string `db:"created_at" json:"created_at"` - Likes int `db:"likes" json:"likes" validate:"numeric"` - Bookmarks int `db:"bookmarks" json:"bookmarks" validate:"numeric"` - ReplyingTo null.Int `db:"replying_to" json:"replying_to" validate:"omitempty,numeric"` -} - - -type Bookmark struct { - MessageId int `db:"message_id" json:"message_id" validate:"required,numeric"` - UserId int `db:"user_id" json:"user_id" validate:"required,numeric"` + HasMaybe null.Int `db:"replying_to" json:"replying_to" validate:"omitempty,numeric"` } func Models() map[string]reflect.Type { return map[string]reflect.Type{ "user": reflect.TypeFor[User](), - "message": reflect.TypeFor[Message](), - "bookmark": reflect.TypeFor[Bookmark](), + "null_example": reflect.TypeFor[NullExample](), } }