diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-05-12 13:23:39 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-05-12 13:25:00 +0200 |
| commit | 80c3fadf24fe9d784d876eec247fd6799af49c8a (patch) | |
| tree | 81b527133fdf192f187aaa4f5cf4f5187bb1a45d | |
| parent | 14ae9e47a2a303726f8e5141cfd46bb22e0f51c6 (diff) | |
| download | go-oblast-80c3fadf24fe9d784d876eec247fd6799af49c8a.tar.gz | |
clarify docstrings, put down TODOs based on review feedback
| -rw-r--r-- | dialect.go | 4 | ||||
| -rw-r--r-- | query.go | 7 |
2 files changed, 8 insertions, 3 deletions
@@ -88,9 +88,9 @@ func (d postgresDialect) UpsertClause(pkColumns, otherColumns []string) string { } } -// SqliteDialect is the dialect of SQLite 3.24.0+ databases. +// SqliteDialect is the dialect of SQLite 3.35.0+ databases. // -// This dialect does NOT support ancient SQLite versions (3.24.0 was released 2018-06-04) +// This dialect does NOT support ancient SQLite versions (3.35.0 was released 2021-03-12) // that do not understand the "INSERT ... RETURNING" syntax. func SqliteDialect() Dialect { return sqliteDialect{} @@ -38,6 +38,7 @@ func prepare(ctx context.Context, db Handle, query, operation string, inputSize // // Fields that are declared with the "auto" tag will not be written into the DB, // and instead their value (as auto-generated by the DB on insert) will be placed in the record. +// (This is why this method, as well as [Store.Upsert], need to take their arguments by-pointer instead of by-value). // // Returns an error if [NewStore] was called without the [TableNameIs] option, which is required to generate a query for this method. // @@ -77,6 +78,7 @@ func (s Store[R]) insertUsing(ctx context.Context, stmt handle.Statement, db Han } func insertRecord(ctx context.Context, v reflect.Value, recordIndex int, stmt handle.Statement, argumentIndexes [][]int, argumentSlots []any, scanIndexes [][]int, scanSlots []any) error { + // TODO: check plan.IndexesOfTransparentPointerStructs, return error (instead of panicking on FieldByIndex) if pointer struct is nil for idx, index := range argumentIndexes { argumentSlots[idx] = v.FieldByIndex(index).Interface() } @@ -132,6 +134,7 @@ func (s Store[R]) Update(ctx context.Context, db Handle, records ...R) error { } func updateRecord(ctx context.Context, v reflect.Value, recordIndex int, stmt handle.Statement, argumentIndexes [][]int, argumentSlots []any) (int64, error) { + // TODO: check plan.IndexesOfTransparentPointerStructs, return error (instead of panicking on FieldByIndex) if pointer struct is nil for idx, index := range argumentIndexes { argumentSlots[idx] = v.FieldByIndex(index).Interface() } @@ -175,6 +178,8 @@ func (s Store[R]) Delete(ctx context.Context, db Handle, records ...R) error { } func deleteRecord(ctx context.Context, v reflect.Value, recordIndex int, stmt handle.Statement, argumentIndexes [][]int, argumentSlots []any) error { + // TODO: consider checking plan.IndexesOfTransparentPointerStructs and returning an error (instead of panicking on FieldByIndex) if pointer struct is nil + // (might want to have bookkeeping to only check pointer structs that lead to PK fields) for idx, index := range argumentIndexes { argumentSlots[idx] = v.FieldByIndex(index).Interface() } @@ -188,7 +193,7 @@ func deleteRecord(ctx context.Context, v reflect.Value, recordIndex int, stmt ha // Upsert executes either an SQL INSERT or UPDATE statement for each of the provided records, // based on whether the record already exists in the DB or not. // -// - For record types that have fields declared with the "auto" tag, INSERT is chosen iff those fields hold zero values. +// - For record types that have fields declared with the "auto" tag, INSERT is chosen if and only if those fields hold zero values. // Returns an error if only some of the respective fields hold zero values while others don't. // Returns an error if [NewStore] was called without the [TableNameIs] or [PrimaryKeyIs] options, which are both required to generate the respective queries for this method. // - For record types that do not have fields declared with the "auto" tag, an INSERT ... ON CONFLICT statement is used. |
