Scanning
biref.scan() produces a DataModel containing every entity the adapter discovered.
Basic usage
// Default namespace (Postgres: 'public', MySQL: connected database)
const model = await biref.scan();
// Specific namespaces
const model = await biref.scan({
namespaces: ['public', 'auth', 'billing'],
});
// Every non-system namespace
const model = await biref.scan({ namespaces: 'all' });
Filtering entities
Apply allowlists or denylists after namespace filtering:
// Only scan these tables
const model = await biref.scan({
namespaces: ['public'],
includeEntities: ['users', 'orders', 'products'],
});
// Scan everything except these
const model = await biref.scan({
namespaces: ['public'],
excludeEntities: ['audit_log', 'schema_migrations'],
});
Multi-adapter setups
const biref = Biref.builder()
.withAdapter(postgresAdapter.create(pgClient))
.withAdapter(mysqlAdapter.create(mysqlConn))
.build();
// Pick by adapter name
const pgModel = await biref.scan('postgres');
const myModel = await biref.scan('mysql');
// Route by URL scheme
const model = await biref.scanByUrl('postgres://localhost/mydb');
Inspecting the model
// Count entities
console.log(model.entities.length);
// Look up a specific entity
const users = model.getEntity('public', 'users');
// Check existence
model.hasEntity('public', 'users'); // true
// Iterate
for (const entity of model.entities) {
console.log(`${entity.namespace}.${entity.name}`);
console.log(` Fields: ${entity.fields.length}`);
console.log(` PK: ${entity.identifier.join(', ')}`);
console.log(` Relationships: ${entity.relationships.length}`);
}
IntrospectOptions
| Field | Type | Effect |
|---|---|---|
namespaces | readonly string[] | 'all' | Namespaces to scan. Omit for the adapter's default. |
includeEntities | readonly string[] | Allowlist applied after namespace filtering. |
excludeEntities | readonly string[] | Denylist applied after namespace filtering. |