surrealdb.schema
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

SurrealDB Logo SurrealDB Logo

SurrealDB Schema

Description

This package provides functionality for parsing SurrealDB schema information from the database API, it then proves classes/structure for those parsed definitions.

Installation

To install this package, run the following command in your project directory:

npm install surrealdb.schema
yarn add surrealdb.schema

Usage

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"]);

Schema:

interface ISchema {
	tables: { [name: string]: SchemaTable };
	hasTable(name: string): boolean;
	getTable(name: string): SchemaTable;
	getTables(): SchemaTable[];
	getTableNames(): string[];
	getFullSchema(): string;
}

Table

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;
}

Field

interface ISchemaField {
	originalString: string;
	name: string;
	title: string;
	table: string;
	type: string;
	record: string;
	assert: string;
	child: SchemaField;
	isArrayChild: boolean;
}

Contributing

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.

License

This package is licensed under the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i surrealdb.schema

Weekly Downloads

1

Version

0.0.12

License

MIT

Unpacked Size

275 kB

Total Files

23

Last publish

Collaborators

  • itsmrsammeh