diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-04-14 00:50:20 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-04-14 00:50:20 +0200 |
| commit | d75031ffd1667c330ccc281ea330503eaeaea88a (patch) | |
| tree | 91a22017fbf2d05335f009fadcb146892e235db1 /oblast.go | |
| parent | 9191e018ff90deb99f3881966a5d356a05027e0f (diff) | |
| download | go-oblast-d75031ffd1667c330ccc281ea330503eaeaea88a.tar.gz | |
fold package internal into package oblast
Diffstat (limited to 'oblast.go')
| -rw-r--r-- | oblast.go | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -42,24 +42,23 @@ package oblast // import "go.xyrillian.de/oblast" import ( "database/sql" + "fmt" "reflect" - - "go.xyrillian.de/oblast/internal" ) // PlanOption is an option that can be given to NewStore() to influence query planning for a certain type of record. -type PlanOption func(*internal.PlanOpts) +type PlanOption func(*planOpts) // TableNameIs is a PlanOption for record types that correspond to exactly one database table (as opposed to a join of multiple tables). // This option is required to enable any of the methods of [Store] that use partially or fully auto-generated query strings. func TableNameIs(name string) PlanOption { - return func(opts *internal.PlanOpts) { opts.TableName = name } + return func(opts *planOpts) { opts.TableName = name } } // PrimaryKeyIs is a PlanOption for record types that correspond to a database table with a primary key. // This option is required to enable use of the [Store.Update] and [Store.Delete] methods. func PrimaryKeyIs(columnNames ...string) PlanOption { - return func(opts *internal.PlanOpts) { opts.PrimaryKeyColumnNames = columnNames } + return func(opts *planOpts) { opts.PrimaryKeyColumnNames = columnNames } } // Handle is an interface for functions providing direct DB access. @@ -83,7 +82,7 @@ var ( // and can also be used to execute autogenerated queries if the respective [PlanOption] values were provided during [NewStore]. type Store[R any] struct { dialect Dialect - plan internal.Plan + plan plan } // NewStore initializes a store for record type R. @@ -110,11 +109,15 @@ type Store[R any] struct { // Besides the declaration of a column name, the following extra tags are understood (as a comma-separated list following the column name): // - "auto": During [Store.Insert], do not store this field's value. Instead, the database will auto-generate a value, which will be read back into the record. func NewStore[R any](dialect Dialect, opts ...PlanOption) (Store[R], error) { - var popts internal.PlanOpts + var popts planOpts for _, opt := range opts { opt(&popts) } - plan, err := internal.BuildPlan(reflect.TypeFor[R](), dialect, popts) + plan, err := buildPlan(reflect.TypeFor[R](), dialect, popts) + if err != nil { + var zero R + return Store[R]{}, fmt.Errorf("cannot use type %T for queries: %w", zero, err) + } return Store[R]{dialect, plan}, err } |
