.InsertRelation[T](table, data)
Inserts one or multiple relations in the database.
Method Syntaxdb.InsertRelation[T](table, data)
Arguments | Description | ||
---|---|---|---|
table required | Optionally pass along a table to insert into. | ||
data required | Either a single document/record or an array of documents/records to insert |
type Likes struct { ID models.RecordID `json:"id"` In models.RecordID `json:"in"` Out models.RecordID `json:"out"` } // Insert a single record into the "likes" relation like, err := surrealdb.InsertRelation[Likes](db, models.Table("likes"), map[interface{}]interface{}{ "in": models.NewRecordID("person", "tobie"), "out": models.NewRecordID("post", "123"), }) if err != nil { panic(err) } fmt.Printf("Inserted single like relation: %+v\n", like) // Insert multiple records into the "likes" relation likes, err := surrealdb.InsertRelation[[]Likes](db, models.Table("likes"), []map[interface{}]interface{}{ { "in": models.NewRecordID("person", "tobie"), "out": models.NewRecordID("post", "123"), }, { "in": models.NewRecordID("person", "jaime"), "out": models.NewRecordID("post", "456"), }, }) if err != nil { panic(err) } fmt.Printf("Inserted multiple like relations: %+v\n", likes)