Add db uuid4 func and uuid insert message param
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user