* Added map layout * Cleanup and bug fixes * Removed package-lock * Cleanup and fixes * Small fix * Added back package-lock * Saved camera, autofitting option, bug fixes * Refactor and ui improvements * Improvements * Added seled mode * Removed unused dependency * Changed selection behaviour, cleanup. * update import and dependencies * make custom style into drawer * remove unused imports * use lodash functions * add popups * allow header to become small * reorganize settings * add styling to popup * change default template * add projection option * add basic map interface * finish simple map * add mapbox style * support more mapbox layouts * add api key option * add mapbox backgrounds to layout * warn when no api key is set * fix for latest version * Improved map layout and interface, bug fixes, refactoring. . . * Added postgis geometry format, added marker icon shadow * Made map buttons bigger and their icons thinner. Added transition to header bar. * Bug fixes and error handling in map interface. * Moved box-select control out of the map component. Removed material icons sprite and use addImage for marker support. * Handle MultiGeometry -> Geometry interface error. * Removed hardcoded styles. Added migrations for basemap column. Lots of refactoring. Removed hardcoded styles. Added migrations for basemap column. Lots of refactoring. * Fixed style reloading error. Added translations. * Moved worker code to lib. * Removed worker code. Prevent Mapbox from removing access_token from the URL. * Refactoring. * Change basemap selection to in-map dropdown for layout and interface. * Touchscreen selection support and small fixes. * Small change. * Fixed unused imports. * Added support for PostgreSQL identity column * Renamed migration. Added crs translation. * Only show fields using the map interface in the map layout. * Removed logging. * Reverted Dockerfile change. * Improved crs support. * Fixed translations. * Check for schema identity before updating it. * Fixed popup not updating on feature hover. * Added feature hover styling. Fixed layer customization input. Added out of bounds error handling. * Added geometry type and support for database native geometries. * Fixed linting. * Fixed layout. * Fixed layout. * Actually fixed linting * Full support for native geometries Fixed basemap input Improved feature popup on hover Locked interfaced support * Fixed geometryType option not updating * Bug fixes in interface * Fixed crash when empty basemap settings. Fixed fitBounds option not updating. * Added back storage type option. Improved interface behaviour. * Dropped wkb because of vendor inconsistency with binary data * Updated layout to match new geometry type. Fixed geojson payload transform. * Added missing geometry_format attributes to local types. * Fixed typos & refactoring * Removed dependency on proj4 * Fix error when empty map interface options * Set geometry SRID to 4326 when inserting into the database * Add support for selectMode * Fix error on initial source load * Added geocoder, use GeoJSON for api i/o, removed geometry_format option, refactoring * Added geometry intersects filter. Created geometry helper class. * Fix error when null geometryOptions, added mapbox_key setting. * Moved all geometry parsing/serializing into processGeometries in `payload.ts`. Fixed type errors. * Migrate to Vue 3 * Use wellknown instead of wkx * Fixed basemap selection. * Added available operator for geometry type * Added nintersects filter, fixed map interface for filter input * Added intersects_bbox filter & bug fixes. * Fixed icons rendering * Fixed cursor icon in select mode * Added geometry aggregate function * Fixed geometry processing bug when imported from relational field. * Fixed error with geocoder instanciation * Removed @types/maplibre-gl dependency * Removed fitViewToData options * Merge remote-tracking branch 'upstream/main' into map-layout * Fixed style and geometryType in map interface options * Fixed style change on map interface. * Improved fitViewToData behaviour * Fixed type imports and previous merge conflict * Fixed linting * Added available operators * Fix and merge migrations * Remove outdated p-queue dep * Fix get-schema column extract * Replace pg with postgis for local debugging * Re-add missing import * Add mapbox as a basemap when key exists * Remove unused tz flag * Process delta in payloadservice * Set default map, add limit number styling * Default display template to just PK * Tweak styling of error dialog * Fix method usage in helpers * Move sdo_geo to oracle section * Remove extensions from ts config exclude * Move geo types to shared, remove _Geometry * Remove unused type * Tiny Tweaks * Remove fit to bounds option in favor of on * Validate incoming intersects query * Deepmap filter values * Add GraphQL support * No defaultValue for geometryType * Resolve c * Fix translations Co-authored-by: Nitwel <nitwel@arcor.de> Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
@directus/schema
Utility for extracting information about the database schema
Usage
The package is initialized by passing it an instance of Knex:
import knex from 'knex';
import schema from '@directus/schema';
const database = knex({
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'your_database_user',
password: 'your_database_password',
database: 'myapp_test',
charset: 'utf8',
},
});
const inspector = schema(database);
export default inspector;
Examples
import inspector from './inspector';
async function logTables() {
const tables = await inspector.tables();
console.log(tables);
}
API
Note: MySQL doesn't support the schema parameter, as schema and database are ambiguous in MySQL.
Note 2: Some database types might return slightly more information than others. See the type files for a specific overview what to expect from driver to driver.
Note 3: MSSQL doesn't support comment for either tables or columns
Tables
tables(): Promise<string[]>
Retrieve all tables in the current database.
await inspector.tables();
// => ['articles', 'images', 'reviews']
tableInfo(table?: string): Promise<Table | Table[]>
Retrieve the table info for the given table, or all tables if no table is specified
await inspector.tableInfo('articles');
// => {
// name: 'articles',
// schema: 'project',
// comment: 'Informational blog posts'
// }
await inspector.tableInfo();
// => [
// {
// name: 'articles',
// schema: 'project',
// comment: 'Informational blog posts'
// },
// { ... },
// { ... }
// ]
hasTable(table: string): Promise<boolean>
Check if a table exists in the current database.
await inspector.hasTable('articles');
// => true
Columns
columns(table?: string): Promise<{ table: string, column: string }[]>
Retrieve all columns in a given table, or all columns if no table is specified
await inspector.columns();
// => [
// {
// "table": "articles",
// "column": "id"
// },
// {
// "table": "articles",
// "column": "title"
// },
// {
// "table": "images",
// "column": "id"
// }
// ]
await inspector.columns('articles');
// => [
// {
// "table": "articles",
// "column": "id"
// },
// {
// "table": "articles",
// "column": "title"
// }
// ]
columnInfo(table?: string, column?: string): Promise<Column[] | Column>
Retrieve all columns from a given table. Returns all columns if table parameter is undefined.
await inspector.columnInfo('articles');
// => [
// {
// name: "id",
// table: "articles",
// type: "VARCHAR",
// defaultValue: null,
// maxLength: null,
// isNullable: false,
// isPrimaryKey: true,
// hasAutoIncrement: true,
// foreignKeyColumn: null,
// foreignKeyTable: null,
// comment: "Primary key for the articles collection"
// },
// { ... },
// { ... }
// ]
await inspector.columnInfo('articles', 'id');
// => {
// name: "id",
// table: "articles",
// type: "VARCHAR",
// defaultValue: null,
// maxLength: null,
// isNullable: false,
// isPrimaryKey: true,
// hasAutoIncrement: true,
// foreignKeyColumn: null,
// foreignKeyTable: null,
// comment: "Primary key for the articles collection"
// }
primary(table: string): Promise<string>
Retrieve the primary key column for a given table
await inspector.primary('articles');
// => "id"
Misc.
withSchema(schema: string): void
Not supported in MySQL
Set the schema to use. Note: this is set on the inspector instance and only has to be done once:
inspector.withSchema('my-schema');
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Tests
First start docker containers:
$ docker-compose up -d
Then run tests:
$ npm test
Standard mocha filter (grep) can be used:
$ npm test -- -g '.tableInfo'