# surreal-db-helper

> Surrealdb typescript rest helper

Latest version **1.0.0-alpha.6** (published 2022-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install surreal-db-helper
pnpm add surreal-db-helper
yarn add surreal-db-helper
bun add surreal-db-helper
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.6 |
| Published | 2022-09-19 |
| First published | 2022-09-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 28.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | mpoapostolis@gmail.com |
| Maintainers | mpoapostolis |
| Keywords | surreal-db, surrealdb, surrealdb-rest, surreal-db-helper |

## Links

- npm: https://www.npmjs.com/package/surreal-db-helper
- Repository: https://github.com/mpoapostolis/surreal-helper
- Homepage: https://github.com/mpoapostolis/surreal-helper#readme
- Issues: https://github.com/mpoapostolis/surreal-helper/issues
- npm.io page: https://npm.io/package/surreal-db-helper

## Dependencies (2)

- [node-fetch](https://npm.io/package/node-fetch.md) ^3.2.10
- [surreal-db-helper](https://npm.io/package/surreal-db-helper.md) ^0.0.3-alpha

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.0.0-alpha.6 (latest) — 2022-09-19
- 1.0.0-alpha.3 — 2022-09-19
- 1.0.0-alpha.2 — 2022-09-19
- 1.0.0-alpha.1 — 2022-09-19
- 1.0.0-alpha — 2022-09-19
- 0.0.8-alpha.1 — 2022-09-17
- 0.0.8-alpha — 2022-09-17
- 0.0.7-alpha.0.1 — 2022-09-17
- 0.0.7-alpha — 2022-09-17
- 0.0.6-alpha — 2022-09-17
- 0.0.5-alpha — 2022-09-17
- 0.0.4-alpha — 2022-09-17
- 0.0.3-alpha — 2022-09-17
- 0.0.2-alpha — 2022-09-17
- 0.0.1-alpha — 2022-09-17
- … 1 more at https://npm.io/package/surreal-db-helper/versions

## README

# Connection
```ts
import { Surreal } from "surreal-db-helper/dist";

// (url: string, ns: string, db: string, auth?: string)
const surreal = new Surreal({
  url: "http://localhost:8000/sql",
  ns: "mpoapostolis",
  db: "account",
  auth: "root:root",
});

type Res = {
  id: number;
  name: string;
};

const accounts = await surr.rawQuery<Res>(`SELECT * FROM accounts`)
```

## API

### Select

```ts
// select with  id
const users = await surr.select<Res>("*")
    .from("users:mpoapostolis")
    .where({ name: "mpoapostolis" }) // where is required leave it empty if you want to select all

// select all
const account = await surr.select<Res>(["name","age"])
    .from("users")
    .where() // where is required leave it empty if you want to select all


// select with condition
const account = await surr.select<Res>(["table.*","name","age"])
    .from("users")
    .where({
        name: "mpoapostolis",
        age: 31,
        rel: table.id
    }) // where is required leave it empty if you want to select all
```

### Create

```ts
// with id
const user = await surr.create<Res>("users:mpoapostolis")
    .set({ name: "mpoapostolis", age:31  });

const user = await surr.create<Res>("users")
    .set({ name: "mpoapostolis", age:31  });

```

### UPDATE

```ts

import { ops } from "surreal-db-helper/dist";

// update id
const user = await surr.create<Res>("users:mpoapostolis")
    .set({ name: "apostolis", age:32  });
// update many
const user = await surr.create<Res>("users")
    .where(ops.gt("age", 30))
    .set({ name: "mpoapostolis", age:31  });

```


### DELETE

```ts

import { ops } from "surreal-db-helper/dist";

// delete id
const user = await surr.delete<Res>("users:mpoapostolis")
// delete many
const user = await surr.delete<Res>("users")
    .where(ops.gt("age", 30))

```


### RELATIONS

```ts
  const user  = surr.create("users:mpoapostolis")
    .set({ name: "mpoapostolis", age:31  });

  const item  = surr.create("item:sword")
    .set({ owner: "users.mpoapostolis", str:69, hp:420  });

  const mpoapostolisItems = surr.select(["*","owner.name"])
    .from("item")
    .where({ owner: "users.mpoapostolis" })

```


WITHOUT WARRANTY OR CONDITION OF ANY KIND, either express or implied. See the MIT License for more details.

---
_Source: https://npm.io/package/surreal-db-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
