2026-02-14 18:15:07 +00:00
|
|
|
package model
|
|
|
|
|
|
2026-03-05 11:21:41 +00:00
|
|
|
// Options holds configuration for a Model.
|
|
|
|
|
type Options struct {
|
2026-03-04 13:13:34 +00:00
|
|
|
// DSN is the data source name / connection string.
|
|
|
|
|
DSN string
|
2026-02-14 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-05 11:21:41 +00:00
|
|
|
// WithDSN sets the data source name.
|
2026-03-04 13:13:34 +00:00
|
|
|
func WithDSN(dsn string) Option {
|
2026-03-05 11:21:41 +00:00
|
|
|
return func(o *Options) {
|
2026-03-04 13:13:34 +00:00
|
|
|
o.DSN = dsn
|
2026-02-14 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 11:21:41 +00:00
|
|
|
// NewOptions creates Options with defaults applied.
|
|
|
|
|
func NewOptions(opts ...Option) Options {
|
|
|
|
|
o := Options{}
|
2026-03-04 13:13:34 +00:00
|
|
|
for _, opt := range opts {
|
|
|
|
|
opt(&o)
|
2026-02-14 18:15:07 +00:00
|
|
|
}
|
2026-03-04 13:13:34 +00:00
|
|
|
return o
|
2026-02-14 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-04 13:13:34 +00:00
|
|
|
// WithTable overrides the auto-derived table name.
|
2026-03-05 11:21:41 +00:00
|
|
|
func WithTable(name string) RegisterOption {
|
2026-03-04 13:13:34 +00:00
|
|
|
return func(s *Schema) {
|
|
|
|
|
s.Table = name
|
2026-02-14 18:15:07 +00:00
|
|
|
}
|
|
|
|
|
}
|