No commit activity in last 3 years
No release in over 3 years
ODM (Object-Document-Mapper) for the Google Cloud Datastore.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

active_support
>= 0
>= 0
>= 0
>= 0
 Project Readme

ActiveDatastore

With the release of the Google Cloud Datastore API, it's finally possible to leverage the datastore in pretty much any stack. Since Google seems to be supporting NodeJS, Python and Java right of the bat, it makes sense to bridge the Ruby gap.

ActiveDatastore is (eventually) meant to be comparable to ActiveRecord in terms of API, features and ease of use. It will rely heavily on ActiveModel, but will continue to be framework agnostic and usable with or without Rails.

Current Status

I've built a wrapper over the GCD API (ActiveDatastore::Dataset) that's fully functional and can be used for pretty much all the examples given in the documentation. The wrapper's API is very similar to what you see in the NodeJS examples.

Right now, ActiveDatastore is very much a work in progress. Please evaluate it before production use, and do remember that the API may undergo breaking changes until we hit v1.0.

Installation

Add this line to your application's Gemfile:

gem 'active_datastore'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_datastore

Usage

Follow the instructions here to get your service account (AUTH_EMAIL), private key (AUTH_KEY) and dataset id (DATASET_ID).

In your initializer (if you're on Rails you could create config/initializers/datastore.rb):

require 'active_datastore'

AUTH_EMAIL = "something@developer.gserviceaccount.com"
AUTH_KEY = File.open("path/to/my/secret.key.p12").read
DATASET_ID = "my-dataset"

client = ActiveDatastore::Client.new AUTH_EMAIL, AUTH_KEY
$dataset = ActiveDatastore::Dataset.new DATASET_ID, client

The initialization of the client is performance / network intensive, so it might make sense to do it once and hold the $dataset for the lifetime of the application. ActiveDatastore::Dataset is stateless and will support this.

To make calls to the datastore, use the methods documented on the JSON API Reference, but remember to use the underscore equivalent names. For example, use begin_transaction instead of beginTransaction.

start_response = $dataset.begin_transaction({
  isolationLevel: "snapshot"
})

start_response.data.kind    # Should be "datastore#beginTransactionResponse"
transaction_id = start_response.data.transaction

rollback_response = $dataset.rollback({
  transaction: transaction_id
})

rollback_response.data.kind    # Should be "datastore#rollbackResponse"  

Both the request body and the response.data are hashes with camel case keys, as shown in the docs. Using camelCase for the request and response while underscore_case for the method names is a little inconsistent, but any effort to deeply walk through each hash and convert keys will probably be more trouble than it's worth.

Contributing

  1. Fork the repo
  2. Create your feature branch (git checkout -b bug-fix)
  3. WRITE GOOD AND CLEAR TESTS. Do remember that this gem may be used in production to serve millions of requests. Bugs can be catastrophic. Also, I can't merge and maintain code I don't fully understand.
  4. Commit your changes (git commit -am 'Fixed bug!')
  5. Push to the branch (git push origin bug-fix)
  6. Create new Pull Request

Please do the same for features you'd like to add, but send the pull request fast and early so we can talk about it and not do things twice. Pull requests are conversations.