Documentation
¶
Overview ¶
Package dalgoschema is a schemer.SchemaProvider built on DALgo's dbschema.SchemaReader, so one scanner serves every database whose DALgo adapter can read its own schema. PostgreSQL is the first.
A SchemaReader describes a table by name and keeps native names and types out of reach, so what a scan can report is what the reader reports: the portable column type (a type the reader cannot map is a string), the primary key, foreign keys, unique constraints and indexes, under the exact names the reader returns. A SchemaReader cannot tell a view from a table, so unless the reader also is a ViewLister every collection is reported as a table (the PostgreSQL reader of dalgo2postgres is not one yet: a view of its server is a table of the scan); a collection is in the schema its reference names, or else in the schema the provider was given, which is the only one a reader that lists no schema in its references reads, so for that reader a foreign key into another schema is left out of the scan.
A scan opens connections to somebody's server, so the provider bounds how many reads and counts it has in flight at once (maxConcurrentReads): the core scanner starts a goroutine per table for each of them, and without a bound a schema of a few dozen tables would ask for more connections than a default PostgreSQL server grants.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSchemaProvider ¶
func NewSchemaProvider(reader dbschema.SchemaReader, counter RecordsCounter, catalog, schema string) schemer.SchemaProvider
NewSchemaProvider returns a schemer.SchemaProvider that reads catalog through reader. schema is the schema the reader inspects: every collection whose reference does not name another is reported in it. counter may be nil, in which case no table has a record count.
The provider is safe for the concurrent use the scanner makes of it: it reads each table's description, indexes and constraints once and shares them, and it never has more than maxConcurrentReads calls to reader and counter in flight.
Types ¶
type RecordsCounter ¶
type RecordsCounter interface {
CountRecords(ctx context.Context, schema, table string) (*int, error)
}
RecordsCounter reads the number of records of one table. A nil count with a nil error means the count is not available, which is not the same as zero.
func NewNativeCounter ¶
func NewNativeCounter(db dal.DB) RecordsCounter
NewNativeCounter counts a table's records with one COUNT(*) structured query, and only when db runs that aggregate natively.
A database that does not advertise a native COUNT would have DALgo read every row of the table through this process and count them here. A schema scan must never do that to someone's database, so such a table has no count: the count is unknown, and it appears on its own once the database's adapter declares the aggregate.
type ViewLister ¶ added in v0.55.0
type ViewLister interface {
ListViews(ctx context.Context) ([]dal.CollectionRef, error)
}
ViewLister is the optional capability of a reader that can tell a view from a table: it lists the collections that are views, each by the reference that ListCollections gave it (a view is among the collections ListCollections lists). A scan reports a collection it lists as a view, and does not count its records.