Add db uuid4 func and uuid insert message param

This commit is contained in:
dwrz
2026-10-09 16:52:31 +00:00
parent f365ccad16
commit e8b239649a
3 changed files with 65 additions and 1 deletions
+9 -1
View File
@@ -313,6 +313,8 @@ type InsertMessageParams struct {
Content string
// ConversationId identifies the conversation that owns the new row.
ConversationId string
// Id is the new row's UUID. Nil generates a version 4 UUID.
Id *uuid.UUID
// Metadata is inference JSON converted to JSONB for storage.
// Nil stores SQL NULL; malformed JSON causes insertion to fail.
Metadata jsontext.Value
@@ -324,6 +326,12 @@ type InsertMessageParams struct {
// InsertMessage creates a new message.
func (q *Queries) InsertMessage(ctx context.Context, arg InsertMessageParams) (*Message, error) {
var id uuid.UUID
if arg.Id == nil {
id = uuid.NewV4()
} else {
id = *arg.Id
}
var metadataArg any
if arg.Metadata != nil {
metadataArg = string(arg.Metadata)
@@ -331,7 +339,7 @@ func (q *Queries) InsertMessage(ctx context.Context, arg InsertMessageParams) (*
row := q.db.QueryRowContext(
ctx,
insertMessage,
uuid.New().String(),
id.String(),
arg.Content,
arg.ConversationId,
metadataArg,