Documentation
¶
Overview ¶
Package ormconnector wires the Lemmego ORM into the application lifecycle.
It opens the connection, publishes *orm.DB to the service container, and optionally registers a GPA provider so code written against gpa.Repository[T] keeps working.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Connect opens a connection and wraps it in an ORM handle.
The DSN is built by the migration module so that the ORM and `lemmego migrate` always resolve the same database from the same settings.
func ConnectWith ¶ added in v0.3.0
ConnectWith opens the connection through a named database/sql driver, rather than the one the dialect is named after.
For an instrumented driver. A wrapper is registered under a name of its own — sql.Register panics on a duplicate, so it cannot take "postgres" — and Connect opens the canonical name, so there was no way to reach one. The dialect still comes from the configured driver, which is what keeps `lemmego migrate` and the ORM generating the same SQL.
sql.Register("postgres-observed", observe.Wrap(&pq.Driver{}))
&ormconnector.Provider{Driver: "postgres-observed"}
An empty name means the canonical one, so this is Connect.
func DialectFor ¶
DialectFor maps a driver name onto an ORM dialect. The names match those the migration module uses, which is what keeps the two in step.
func SupportedDrivers ¶
func SupportedDrivers() []string
SupportedDrivers lists the drivers the connector can open. It is deliberately the same set the migration module supports; SQL Server is absent from both.
Types ¶
type Provider ¶
type Provider struct {
// UseGPA additionally registers a gpaorm provider, so repositories
// resolved through gpa.MustGet keep working while code migrates over.
UseGPA bool
// Connection selects a named connection from the sql config tree.
// Empty means the configured default.
Connection string
// Config overrides the configuration read from the app when set.
Config gpa.Config
// Driver is the registered database/sql driver name to open, when it is
// not the one the dialect is named after.
//
// For an instrumented driver — see ConnectWith. The dialect still comes
// from configuration, so `lemmego migrate` and the ORM stay in step.
Driver string
// contains filtered or unexported fields
}
Provider connects the ORM during application bootstrap.
func (*Provider) AddCommands ¶
AddCommands contributes the descriptor generator as a CLI command, so the framework gains `orm:fields` without the CLI module needing to depend on the ORM.
func (*Provider) Dialect ¶ added in v0.1.3
Dialect reports the SQL flavour of the open connection, completing db.Connection along with Name.
func (*Provider) Name ¶ added in v0.1.3
Name reports which sql.connections key this connection was built from.