This package provides functionality for parsing SurrealDB schema information from the database API, it then proves classes/structure for those parsed definitions.
To install this package, run the following command in your project directory:
npm install surrealdb.schema
yarn add surrealdb.schema
Here is an example of how to use this package to parse your database schema:
import {SurrealSchema} from 'surreal.schema';
const surrealSchema = SurrealSchema.init({
host : "http://127.0.0.1:8000",
user : "root",
pass : "secret",
namespace : "test",
database : "test",
});
await surrealSchema.getSchema(); // Returns `Schema` instance
// There is also:
await surrealSchema.getDbInfo();
await surrealSchema.getTableInfo("table name");
await surrealSchema.getTablesInfo(["one", "two"]);
interface ISchema {
tables: { [name: string]: SchemaTable };
hasTable(name: string): boolean;
getTable(name: string): SchemaTable;
getTables(): SchemaTable[];
getTableNames(): string[];
getFullSchema(): string;
}
interface ISchemaTable {
originalString: string;
name: string;
title: string;
fields: { [name: string]: SchemaField };
hasField(name: string): boolean;
getField(name: string): SchemaField;
getFieldNames(): string[];
getFields(): SchemaField[];
getFullSchema(): string;
}
interface ISchemaField {
originalString: string;
name: string;
title: string;
table: string;
type: string;
record: string;
assert: string;
child: SchemaField;
isArrayChild: boolean;
}
We welcome contributions to this package! If you have an idea for a new feature or a bug fix, please open an issue or submit a pull request.
This package is licensed under the MIT License.