An open API service indexing awesome lists of open source software.

https://github.com/idevelopthings/surrealdb-schema

This package provides functionality for parsing SurrealDB schema information from the database API, it then proves classes/structure for those parsed definitions.
https://github.com/idevelopthings/surrealdb-schema

database schema surrealdb typescript

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        




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:
```bash
npm install surrealdb.schema
yarn add surrealdb.schema
```

## Usage
Here is an example of how to use this package to parse your database schema:

```typescript
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:

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

### Table
```typescript
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
```typescript
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](https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt).