I'm using bun with mssql driver, trying to do something simple such as inserting but can't figure out how exactly. Using .Returning("SCOPE_IDENTITY()") doesn't seem to be working properly with mssql.
type Person struct {
bun.BaseModel `bun:"table:Person,alias:p"`
PersonID int `bun:"PersonID,pk,autoincrement"`
Name string `bun:"Name"`
}
// ...
entity := &Person{Name:"John Doe"}
personid := 0
err := db.NewInsert().Model(entity).Scan(context.Background(), &personid) // <-- how do i do that here?
sql that I'm trying to achieve is as below:
INSERT INTO Persons (Name) VALUES ('John Doe'); SELECT SCOPE_IDENTITY()
I'm using bun with mssql driver, trying to do something simple such as inserting but can't figure out how exactly. Using .Returning("SCOPE_IDENTITY()") doesn't seem to be working properly with mssql.
sql that I'm trying to achieve is as below: