Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/kevinmichaelchen/surreal-demo


https://github.com/kevinmichaelchen/surreal-demo

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

Taking [SurrealDB][surreal] for a spin. The domain I'm interested in exploring is wide, high-branching-factor trees, like the _organizational unit_ structures you'd find in [LDAP][ldap] systems. Imagine a forest of millions of trees, where each tree can have an arbitrary height (going up to, say, 10) and potentially thousands of children (“subordinate OUs”).

[surreal]: https://surrealdb.com/
[ldap]: https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol

## Starting

[run-docker]: https://docs.surrealdb.com/docs/installation/running/docker

Spin up the database [with Docker][run-docker]:

```shell
docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:latest start
```

Create some data with:

```shell
go run main.go
```

## GUI

Surrealist has the most GitHub stars — by a long shot — so visit
https://surrealist.app and start a new session.

## Query

```
-- Select ancestors and descendants of Org Unit 123
SELECT
/* parent */
<-belongs_to<-org_unit,

/* grandparent */
<-belongs_to<-org_unit<-belongs_to<-org_unit,

/* children */
->belongs_to->org_unit,

/* grandchildren */
->belongs_to->org_unit->belongs_to->org_unit
FROM org_unit:123;
```

returns

```json
[
{
"children": [
"org_unit:cm5m9km1fpl4pmfrtn3g"
],
"grandchildren": [],
"grandparent": [],
"parent": [
"org_unit:cm5m9km1fpl4pmfrtn50",
"org_unit:cm5m9km1fpl4pmfrtn4g"
]
}
]
```

## Experimenting

### Exporting Data

Use the [`export`][export] command to create a new dataset.

[export]: https://docs.surrealdb.com/docs/cli/export/

```shell
pkgx surreal export --namespace default --database default
```

### Importing Dataset

Use the [`import`][import] command to import a dataset.

[import]: https://docs.surrealdb.com/docs/cli/import/

```shell
pkgx surreal import --namespace default --database default
```