예제 #1
0
    def save(self):
        """
        Saves the model instance to the database (blocking), unlike insert() this is an instance method so needs to be called by
        and instantiated model instance::

            from models import MyTestModel

            my_data = {
                    'this_field':       "Hello World",
                    'another_field':    42,
                    'whatever_field':   True
                  }

            model_instance = MyTestModel(my_data)
            model_instance.save()

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, self)
                self.validate()
                ret_obj = this_collection.save(self)

                return ret_obj
예제 #2
0
    def save(self):
        """
        Saves the model instance to the database (blocking), unlike insert() this is an instance method so needs to be called by
        and instantiated model instance::

            from models import MyTestModel

            my_data = {
                    'this_field':       "Hello World",
                    'another_field':    42,
                    'whatever_field':   True
                  }

            model_instance = MyTestModel(my_data)
            model_instance.save()

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, self)
                self.validate()
                ret_obj = this_collection.save(self)

                return ret_obj
예제 #3
0
    def insert(klass, to_insert):
        """
        Insert a model into the database (blocking).

        **Usage:** ::

            from models import MyTestModel

            my_data = {
                    'this_field':       "Hello World",
                    'another_field':    42,
                    'whatever_field':   True
                  }

            MyTestModel.insert(MyTestModel(my_data))

        This will validate the fields before committing them to the database, without having to instantiate a new
        model instance.

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                self.validate()
                ret_obj = this_collection.insert(to_insert)

                return ret_obj
예제 #4
0
    def insert(klass, to_insert):
        """
        Insert a model into the database (blocking).

        **Usage:** ::

            from models import MyTestModel

            my_data = {
                    'this_field':       "Hello World",
                    'another_field':    42,
                    'whatever_field':   True
                  }

            MyTestModel.insert(MyTestModel(my_data))

        This will validate the fields before committing them to the database, without having to instantiate a new
        model instance.

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                self.validate()
                ret_obj = this_collection.insert(to_insert)

                return ret_obj
예제 #5
0
    def delete(self):
        """
        Removes an item form the database, takes a model as input (blocking).
        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, self)
                ret_obj = this_collection.delete([self])

                return ret_obj
예제 #6
0
    def delete_bulk(klass, to_delete):
        """
        Delete items in a batch operation (blocking) - takes a list of models as input
        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = this_collection.delete(to_delete)

                return ret_obj
예제 #7
0
    def delete_bulk(klass, to_delete):
        """
        Delete items in a batch operation (blocking) - takes a list of models as input
        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = this_collection.delete(to_delete)

                return ret_obj
예제 #8
0
    def delete(self):
        """
        Removes an item form the database, takes a model as input (blocking).
        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, self)
                ret_obj = this_collection.delete([self])

                return ret_obj
예제 #9
0
    def insert_async(klass, to_insert, *args, **kwargs):
        """
        Insert a model into the database (non-blocking).

        **Usage:** ::

            from models import MyTestModel

            my_data = {
                    'this_field':       "Hello World",
                    'another_field':    42,
                    'whatever_field':   True
                  }

            yield gen.Task(MyTestModel.insert_async, MyTestModel(my_data))

        This will validate the fields before committing them to the database, without having to instantiate a new
        model instance.

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        cb = kwargs['callback']
        del (kwargs['callback'])

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = yield gen.Task(this_collection.insert, to_insert,
                                         *args, **kwargs)

                cb(ret_obj)
예제 #10
0
    def find_one(klass, *args, **kwargs):
        """
        Find a single object in the database, takes standard PyMongo-style
        input parameters (blocking)::

            thisUser = User.find_one({'username':username}) #Gets a specific user from the DB

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE
        klass.collection_name = klass.__name__

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = this_collection.find_one(*args, **kwargs)

                return ret_obj
예제 #11
0
    def find_one(klass, *args, **kwargs):
        """
        Find a single object in the database, takes standard PyMongo-style
        input parameters (blocking)::

            thisUser = User.find_one({'username':username}) #Gets a specific user from the DB

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE
        klass.collection_name = klass.__name__

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = this_collection.find_one(*args, **kwargs)

                return ret_obj
예제 #12
0
    def find(klass, *args, **kwargs):
        """
        Find a list of objects in the database, takes standard PyMongo-style input
        parameters (blocking)::

            users = User.find({}) #gets all users in the database
            print users

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE
        klass.collection_name = klass.__name__

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = this_collection.find(*args, **kwargs)

                return ret_obj
예제 #13
0
    def find(klass, *args, **kwargs):
        """
        Find a list of objects in the database, takes standard PyMongo-style input
        parameters (blocking)::

            users = User.find({}) #gets all users in the database
            print users

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE
        klass.collection_name = klass.__name__

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = this_collection.find(*args, **kwargs)

                return ret_obj
예제 #14
0
    def delete_bulk_async(klass, to_delete, callback):
        """
        Delete items in a batch operation (non-blocking) - takes a list of models as input
        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = yield gen.Task(this_collection.delete, to_delete)

                callback(ret_obj)
예제 #15
0
    def delete_async(self, callback):
        """
        Removes an item form the database, takes a model as input (non-blocking).
        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, self)
                ret_obj = yield gen.Task(this_collection.delete, [self])

                callback(ret_obj)
예제 #16
0
    def find_one_async(klass, *args, **kwargs):
        """
        Find a single object in the database, takes standard PyMongo-style
        input parameters (non-blocking)::

            thisUser = yield gen.Task(User.find_one,{'username':username}) #Gets a specific user from the DB

        """
        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE
        klass.collection_name = klass.__name__

        cb = kwargs['callback']
        del (kwargs['callback'])

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = yield gen.Task(this_collection.find_one, *args,
                                         **kwargs)

                cb(ret_obj)
예제 #17
0
    def find_async(klass, *args, **kwargs):
        """
        Find a list of objects in the database, takes standard PyMongo-style
        input paramaters (non-blocking)::

            users = yield gen.Task(User.find_async,{}) #gets all users in the database
            print users

        """

        from Mojo.ServerHelpers.RunServer import BACKEND_COLLECTION, DATABASE
        klass.collection_name = klass.__name__

        cb = kwargs['callback']
        del (kwargs['callback'])

        if DATABASE:
            if BACKEND_COLLECTION:
                this_collection = BACKEND_COLLECTION(DATABASE, klass)
                ret_obj = yield gen.Task(this_collection.find, *args, **kwargs)

                cb(ret_obj)