# folderdb

> store files with searchable key value attributes

Latest version **0.1.1** (published 2015-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install folderdb
pnpm add folderdb
yarn add folderdb
bun add folderdb
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2015-02-04 |
| First published | 2015-01-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+13 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jesse Smith |
| Maintainers | jessebsmith |
| Keywords | file, attributes, database, mongo, key, value |

## Links

- npm: https://www.npmjs.com/package/folderdb
- Repository: https://github.com/jessebsmith/folderdb
- Issues: https://github.com/jessebsmith/folderdb/issues
- npm.io page: https://npm.io/package/folderdb

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) 3.0.0
- [fs-extra](https://npm.io/package/fs-extra.md) 0.15.0
- [mongoose](https://npm.io/package/mongoose.md) 3.8.9

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2015-02-04
- 0.1.0 — 2015-01-30

## README

# folderdb

folderdb allows you to store files with searchable key value attributes.

This makes it easier to keep track of files across applications as well as within an application.

## Requirements

folderdb uses Mongo to store attributes

## Install

    npm install folderdb

## Setup

```javascript

    var folderdb = require('folderdb')

    // set up configuration
    var options = {
      name: 'myFolder',
      path: './myFolder', // Location to store files
      mongo: {
        connectionString: 'mongodb://localhost:27017/test',
        collectionPrefix: 'myfolder'
      }
    }

    // init a local folder for storing files
    var myFolder = folderdb.LocalFolder(options)

```

## API

__store(filePath, attributes, fn)__

Moves the file to folder location and stores any attributes to mongo. Returns
 the file's ObjectId.

```javascript

    myFolder.store('path/to/file', {attribute1: value, attribute2: value}, fn(fileId) {})

```

__replace(id, filePath, fn)__

Replaces an existing file. Updates file name and extension from new file.

```javascript

    myFolder.replace(fileId, 'path/to/new/file', fn(file) {})

```

__update(id, attributes, fn)__

Replaces all the attributes for a file.

```javascript

    myFolder.update(fileId, {attribute3: value, attribute4: value}, fn(file) {})

```


__delete(id, fn)__

Deletes the file.

```javascript

    myFolder.delete(fileId, fn() {})

```

__find(id, fn)__

Returns the file object.

```javascript

    myFolder.find(fileId, fn(file) {})

```

__query(conditions, options, fn)__

Returns a list of files that meet all conditions.

```javascript

    // Compare functions include: $gt, $gte, $lt, $lte
    var conditions = {
      attribute1: 'string',
      attribute2: { $gt: 1 },
      attribute3: { $lt: new Date() }
    }

    // If options are not supplied defaults are used 
    // var options = {
    //   skip: 0,
    //   limit: 100
    // }
    
    myFolder.query(conditions, options, fn(listOfFiles) {
      // listOfFiles[0].attributes = {
      //   attribute1: 'string',
      //   attribute2: 2,
      //   attribute3: Thu Jan 1 2015 15:00:00 GMT-0800 (PST)
      // }
    })

```


__read(id, readOptions, fn)__

Returns the file's data and file object.

```javascript

    // Same options as fs.readFile
    var readOptions = {
      encoding: 'UTF-8',
      flag: 'r'
    }
    myFolder.read(fileId, readOptions, fn(data, file) {})

```

__attributes(fn)__

Returns a list of used attributes.

```javascript

    myFolder.attributes(fn(listOfAttributes) {
      // listOfAttributes = [
      //   'attribute1', 
      //   'attribute2', 
      //   'attribute3',
      //   'attribute4'
      // ]
    })

```

## Notes

### File Object

```javascript

    [ 
      { _id: 54cae43f9f5be0dd3ee02ae3,
        folder: 'myFolder',
        name: 'fileName.jpg',
        attributes: { 
            attribute1: value,
            attribute2: value
        }
      }
    ]

```

### Attributes

Attributes can be defined one of two ways when saving or updating. However, they
 will be saved as an object and not as an array.

```javascript
    
    // valid
    var attributes1 = [
        {attribute1: value},
        {attribute2: value},
    ]
    myFolder.store('path/to/file', attributes1, function(fileId) {})
    
    // also valid
    var attributes2 = {
        attribute1: value,
        attribute2: value,
    }
    myFolder.store('path/to/file', attributes2, function(fileId) {})

```

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