github.com/CodeSteak/Nuummite

Nuummite is a tiny persistent embedded key-value store for Crystal!

28 stars
0 dependents
License: MIT

Nothing has been indexed for 0.1.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  nuummite:
    github: CodeSteak/Nuummite
    version: ~> 0.1.1

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.1. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

Documentation

Read the API documentation

Generated from the source of the current release. The first visit to a release that has never been documented starts its build.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

<img src="https://raw.githubusercontent.com/codesteak/nuummite/master/docs/nuummite.png" width="25%" align="right">

# Nuummite [![Build Status](https://travis-ci.org/CodeSteak/Nuummite.svg?branch=master)](https://travis-ci.org/CodeSteak/Nuummite)

Nuummite is a tiny persistent embedded key-value store. All data is kept
in RAM (in a Crystal Hash) and is also written to disk.
So don't use Nuummite to handle big chunks of data.
Keys and Values are always Strings.
It just comes with the most basic operations.


## Installation

Add this to your application's `shard.yml`:

```yaml
dependencies:
  nuummite:
    github: codesteak/nuummite
    version: ~> 0.1.4
```


## Usage

```crystal
require "nuummite"
```

#### Open the database
```crystal
db = Nuummite.new("path/to/folder", "optional-filename.db")

# You can also have multiple:
flowers  = Nuummite.new("flowers")
minerals = Nuummite.new("minerals")
```

#### Put some values in
```crystal
db["hello"] = "world"
db["42"] = "Answer to the Ultimate Question of Life, The Universe, and Everything"
db["whitespace"] = "Hey\n\t\t :D"
```

#### Read values
```crystal
db["hello"]? # => "world"
db["ehhhh"]? # => nil

#Note: db is locked while reading, so don't write to db!
db.each do |key,value|
  # reads everything
end

db["crystals/ruby"] = "9.0"
db["crystals/quartz"] = "~ 7.0"
db["crystals/nuummite"] = "5.5 - 6.0"

db.each("crystals/") do |key,value|
  # only crystals in here
end
```

#### Delete
```crystal
db.delete "hello"
```

#### Garbage collect
Since values are saved to disk in a log style, file sizes grow,
your key-value store needs to rewrite all data at some point:
```crystal
db.garbage_collect
```
By default it auto garbage collects after 10_000_000 writes.
To modify this behavior you can:
```crystal
# garbage collects after 1000 writes or deletes
db.auto_garbage_collect_after_writes = 1000

# does not auto garbage collect
db.auto_garbage_collect_after_writes = nil  
```

#### Shutdown
You can also shutdown Nuummite by
```crystal
db.shutdown
```

That's all you need to know :smile:

## Contributing

1. Fork it ( https://github.com/codesteak/nuummite/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request

## Contributors

- [CodeSteak](https://github.com/CodeSteak) - creator, maintainer