Skip to content

Commit be5c72b

Browse files
committed
Update README.md
1 parent 3f65fe7 commit be5c72b

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ sequel.RegisterVirtualFunc("BOOL", func(driverName string, args string) (string,
163163
expanded, err := db.UnpackQuery("SELECT * FROM t WHERE updated_at > DATE_ADD_MILLIS(NOW_UTC(), ?) AND active = ?")
164164
```
165165

166+
### InsertReturnID
167+
168+
`InsertReturnID` executes an INSERT statement and returns the auto-generated ID for the named ID column. Each driver uses its native mechanism:
169+
170+
| Driver | Mechanism |
171+
|------------|------------------------------------------|
172+
| MySQL | `LastInsertId()` from the result |
173+
| PostgreSQL | Appends `RETURNING <idColumn>` to the query |
174+
| SQL Server | Injects `OUTPUT INSERTED.<idColumn>` before `VALUES` |
175+
176+
```go
177+
id, err := db.InsertReturnID(ctx, "id", "INSERT INTO users (name, email) VALUES (?, ?)", name, email)
178+
```
179+
166180
### DriverName()
167181

168182
`DriverName()` returns the active driver name (`"mysql"`, `"pgx"`, or `"mssql"`) for cases where you need driver-specific logic in Go code.

0 commit comments

Comments
 (0)