3 unstable releases

0.2.1 Sep 13, 2024
0.2.0 Sep 11, 2024
0.1.0 Aug 18, 2024

#346 in Configuration

24 downloads per month

MIT license

26KB
412 lines

Absurd

A command line tool for managing stores in Surreal DB.

Installation

Absurd is available on crates.io, and requires that you also have cargo installed.

cargo install absurd

That's it!

Usage

Absurd should be run within the root of your project.
Running absurd -h will display the following output.

Command line tool for managing Surreal stores.

Usage: absurd <COMMAND>

Commands:
  create    Specify which type of component you want to create
  help      Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

A component is one of Controller, Model, or Store.
You can think of these components as the following:

  • Controller Controllers are a layer in between your models and stores
  • Model Models represents any record from the store
  • Store Stores handles the connection to a database

Usage Examples

Create a new store

Currently there is only support for the Mem and RocksDB engines.
In the future, we plan to add support for all available SurrealDB engines including Ws.

# Create a store called General, using the Mem engine.
# This creates an in memory store, where no data is persisted.
absurd create store General
absurd create store General --engine mem

# Create a store called Setting, that stores the data in a file.
absurd create store Setting --engine rocks-db

Create a new model

Models are a way to map your database records to a Rust struct.

There are two available table schemas available in SurrealDB: Schemaless and Schemafull.
By default, Schemafull will be selected, unless the model name is passed like Setting/Dark without any --fields.

A Schemafull table will be a single struct, where each field is a property of the struct.
A Schemaless table will be a struct with a single field, where the value is a map of the record.

All models will be given the id with the type Option<Thing>.
This is set to optional as it makes it easier to create new records without having to create a new struct.

# All fields will be given the data type of String. Support may be added to set
# the data type in the CLI.

# Creates a Schemafull model called User, with the fields name and email.
# User { id: Option<Thing>, name: String, email: String }
absurd create model User --fields name email
absurd create model User --fields name email --schemafull

# Create a Schemaless model called Setting, with the fields name and value.
# SettingDark { id: Option<Thing>, name: String, value: String }
absurd create model Setting/Dark
absurd create model Setting --fields dark --schemaless

Dependencies

~1.5–2.1MB
~37K SLoC