SurrealDB Docs Logo

Enter a search query

.Upsert[T](table, data)

Creates or updates a specific record.

Method Syntax
db.Upsert[T](table, data)
Note

This function creates a new document / record or replaces the current one with the specified data.

Arguments

ArgumentsDescription
table required

The table to upsert the record to.

data required

The document / record data to upsert.

Example usage

// Upsert a record in the "persons" table person, err := surrealdb.Upsert[Person](db, models.Table("persons"), Person{ Name: "John", Surname: "Doe", Location: models.NewGeometryPoint(-0.11, 22.00), }) if err != nil { panic(err) } fmt.Printf("Upserted person with a struct: %+v\n", person)

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install