Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/ondra-m/textdb

Textdb is a database which structure is determined by folders and data are represented by files.
https://github.com/ondra-m/textdb

Last synced: 13 days ago
JSON representation

Textdb is a database which structure is determined by folders and data are represented by files.

Awesome Lists containing this project

README

        

# Textdb

Textdb is a database which structure is determined by folders and data are represented by files.

Current state: **beta version**.

Example:
```ruby
# .
# |-- key1
# | |-- key1_1
# | | `-- value1_1_1.data
# | `-- value1_1.data
# `-- key2
# `-- value2_1.data

{
'key1' => {
'key1_1' => {
'value1_1_1' => 'text'
},
'value1_1_1' => 'text'
},
'key2' => {
'value2_1' => 'text'
}
}

```

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'text-db'
```

And then execute:

```bash
$ bundle
```

Or install it yourself as:

```bash
$ gem install text-db
```

## Configuration

`Textdb.config` or `Textdb.configuration(&block)`.

How:
```ruby
Textdb.configuration do
key "/tmp/1"
end

# --- OR ---

Textdb.config.key = "/tmp/1"
```



Key
Default
Description



base_folder
/tmp/textdb
The root folder for Textdb. Folder must exist.


data_file_extension
.data
Extension for data files.


listen
false
Automatic listening for changes in the root folder

## Usage

Folder structure:
```
.
|-- key1
| |-- key1_1
| | `-- key1_1_1
| | |-- value1_1_1_1
| | `-- value1_1_1_2
| |-- value1_1
| `-- value1_2
`-- key2
`-- value2_1
```

### Read

```ruby
Textdb.read { key1 } # -> list of all in the folder /key1
Textdb.read { key2.value2_1 } # -> content of file /key2/value2_1.data
```

### Create

```ruby
Textdb.create { a.b.c } # -> create a file /a/b/c.data
Textdb.create { a.b.c }.update("text") # -> create a file /a/b/c.data with content "text"
```

### Update

`\n` is not included at the end.

```ruby
Textdb.update("text") { a.b.c } # -> update /a/b/c.data with new content
```

### Delete

```ruby
Textdb.delete { key1 } # -> delete everything in the folder /key1
Textdb.delete { key2.value2_1 } # -> delete only /key/value2_1.data
```

## Listen

If **listen** is true.

```ruby
Textdb.read { a.b } # -> "text"

# On FS -------------------------
File.open('/a/b.data', 'w') { |f|
f.write('text 2')
}
# -------------------------------

Textdb.read { a.b } # -> "text 2"
```

## Contributing

1. Fork it
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 new Pull Request