0.3.13 • Published 9 years ago

fireball-db v0.3.13

Weekly downloads
26
License
-
Repository
github
Last release
9 years ago

Fireball

A lightweight model wrapper for DynamoDB with syntax that sucks less.

Getting Started

Install Fireball:

npm install fireball-db --save

Overview

Fireball, in its simplest form, is a wrapper around the AWS SDK DynamoDB Document Client. The primary purpose of this library is to create model object to reflect a single DynamoDB table. The model object provides many useful additions such as unique ID generation, cleaner parameter syntax and promise based functions.

Usage

Import fireball

fireball = require 'fireball-db'

Creating a model object

The model object is a wrapper around the DocumentClient that simplify the parameter syntax to most functions and will automatically add the TableName parameter as needed.

User = fireball.model 'SomeDynamoTable'

Creating a model with custom extensions

User = fireball.model 'SomeDynamoTable',

  find_by_email: (email) ->
    ...

User.find_by_email('test@test.com').then (users) ->
  ...

Promises

All functions of the model object return Promises.

Information on Promises

Querying a table

User = ...
User.query(
  expression: '#field = :value'
  names: {'#field': 'name'}
  values: {':value': 'fred'}
).then (users) ->
  ...

Querying a table with specific index

User = ...
User.query(
  expression: '#field = :value'
  names: {'#field': 'name'}
  values: {':value': 'fred'}
  IndexName: 'secondary_index'
).then (users) ->
  ...

Scanning a table

User = ...
User.scan(
  expression: '#field = :value'
  names: {'#field': 'name'}
  values: {':value': 'fred'}
).then (users) ->
  ...

Getting an item

User = ...
key = email: 'test@email.com'
User.get(key).then (user) ->
  ...

Getting an item by identifier

Wrapper around get that will use the managed identifier key.

User = ...
User.for_id('12312312321').then (user) ->
  ...

Putting an item

User = ...
User.put(first: 'John', last: 'Doe', email: 'test@email.com').then (user) ->
  ...

Putting an item with condition expression

User = ...
user_data = first: 'John', last: 'Doe', email: 'test@email.com'
condition = expression: '#field = :value', names: {'#field': 'name'}, values: {':value': 'fred'}

User.put(user_data, condition).then (user) ->
  ...

Inserting an item

Wrapper around put that will automatically add an identifier field and ensure uniqueness.

User = ...
User.insert(first: 'John', last: 'Doe', email: 'test@email.com').then (user) ->
  ...

Updating an item

User = ...
key = email: 'test@email.com'
User.insert(key, first: 'John', last: 'Doe').then (user) ->
  ...

Deleting an item by key

User = ...
key = email: 'test@email.com'
User.delete(key).then (user) ->
  ...

Deleting an item

User = ...
user = email: 'test@email.com', name: 'someone', ...
User.delete(item).then (user) ->
  ...

Get all items for keys (batchGet)

User = ...
keys = [
  {email: 'test@email.com'}
  {email: 'test2@email.com'}
  {email: 'test3@email.com'}
]
User.for_keys(keys).then (users) ->
  ...

Get all items for identifiers

User = ...
ids = [
  '12121'
  '12122'
  '12123'
]
User.for_ids(ids).then (users) ->
  ...

Putting multiple items (batchWrite)

User = ...
items = [
  {first: 'John', last: 'Doe', email: 'test@email.com'}
  {first: 'Jane', last: 'Doe', email: 'test2@email.com'}
  {first: 'Sally', last: 'Doe', email: 'test3@email.com'}
]
User.put_all(items).then (users) ->
  ...

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

0.3.13

9 years ago

0.3.12

9 years ago

0.3.11

9 years ago

0.3.10

10 years ago

0.3.9

10 years ago

0.3.8

10 years ago

0.3.7

10 years ago

0.3.6

10 years ago

0.3.5

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago