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.
- Host: GitHub
- URL: https://github.com/idevelopthings/surrealdb-schema
- Owner: iDevelopThings
- Created: 2022-12-19T17:57:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-21T20:05:30.000Z (about 2 years ago)
- Last Synced: 2024-04-23T23:47:01.356Z (12 months ago)
- Topics: database, schema, surrealdb, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/surrealdb.schema
- Size: 59.6 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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).