How to use the clay.storage function in clay

To help you get started, we’ve selected a few clay examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yipit / clay.js / test / functional / redis_storage.js View on Github external
var vows = require('vows')
, should = require('should')
, async = require('async')
, fs = require('fs')
, events = require('events')
, _ = require('underscore')._
, path = require('path')
, redis = require('redis');

var client = redis.createClient();

var models = require('clay');
var redis_storage = new models.storage.RedisMechanism(client);

var User = models.declare("User", function(it, kind){
    it.has.field("name", kind.string);
    it.has.field("email", kind.email);
    it.has.field("password", kind.hashOf(["name", "email"]));

    it.has.method('greet', function() {
        return [
            "Hello, my name is ", this.name, ", it's nice to meet you"
        ].join('');
    });
    it.validates.uniquenessOf("name");
    it.has.index('email');
    it.is_stored_with(redis_storage);
});
github Yipit / clay.js / test / unit / issues.js View on Github external
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. */

var vows = require('vows')
, should = require('should')
, crypto = require('crypto')
, _ = require('underscore')._;

var models = require('clay');
var mock = new models.storage.Mechanism();

models.set_primary_storage(mock);

var Foo = models.declare("Foo", function(it, kind){
    it.has.method('work', function(msg){
        return "foooooooooooooooooo"
    });
});

var Bar = models.declare("Bar", function(it, kind){
    it.has.method('work', function(msg){
        return "baaaaarrrrrrrrrrrrr"
    });
});

vows.describe('Model issues').addBatch({
github Yipit / clay.js / test / unit / storage-mechanism.js View on Github external
        function FakeMechanism (){models.storage.Mechanism.call(this)};
        util.inherits(FakeMechanism, models.storage.Mechanism);
github Yipit / clay.js / test / unit / models.js View on Github external
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. */

var vows = require('vows')
, should = require('should')
, crypto = require('crypto')
, _ = require('underscore')._;

var models = require('clay');
var mock = new models.storage.Mechanism();

models.set_primary_storage(mock);

vows.describe('A Model').addBatch({
    'after declared': {
        topic: function () {
            return models.declare("Person", function(it, kind){
                it.has.field("username", kind.alphanumeric);
                it.has.field("email_address", kind.email);
                it.has.field("birthdate", kind.datetime);
                it.has.field("created_at", kind.auto);
                it.has.field("zipcode", kind.numeric);
                it.has.field("password", kind.string);

                it.validates.uniquenessOf("username");
github Yipit / clay.js / test / unit / storage-mechanism.js View on Github external
'it is possible to set the default storage mechanism': function(){
        function FakeMechanismTwo (){models.storage.Mechanism.call(this)};
        util.inherits(FakeMechanismTwo, models.storage.Mechanism);

        var fake2 = new FakeMechanismTwo();

        models.set_primary_storage(fake2)

        var Build = models.declare('Build', function (it, kind){
            it.has.field("name", kind.string);
        });

        assert.deepEqual(fake2, Build._meta.storage);
    },
    'it defaults to the redis storage mechanism': function(){