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. It cannot tell a view from a table, so every collection is reported as a table; and it reads a single schema, so 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 table 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.