Ejemplo n.º 1
0
    def all(cls):
        db_wrap = DBWrapper.get_solo()
        rdb = db_wrap.rdb
        # conn = g.rdb_conn
        conn = db_wrap.connection

        return rdb.table(cls._table).run(conn)
Ejemplo n.º 2
0
 def delete(cls, id):
     db_conn = DBWrapper.get_solo()
     rdb = db_conn.rdb
     conn = g.rdb_conn
     status = r.table(cls._table).get(id).delete().run(conn)
     if status['errors']:
         raise DatabaseProcessError("Could not complete the delete action")
     return True
Ejemplo n.º 3
0
 def filter(cls, predicate, fields=None):
     db_wrap = DBWrapper.get_solo()
     rdb = db_wrap.rdb
     # conn = g.rdb_conn
     conn = db_wrap.connection
     if fields:
         return rdb.table(
             cls._table).filter(predicate).pluck(fields).run(conn)
     return rdb.table(cls._table).filter(predicate).run(conn)
Ejemplo n.º 4
0
    def get(cls, id):
        db_wrap = DBWrapper.get_solo()
        rdb = db_wrap.rdb
        # conn = g.rdb_conn
        conn = db_wrap.connection
        data = rdb.table(cls._table).get(id).run(conn)
        obj = None
        # if data is not None:
        #     obj = cls(**data)

        return data
Ejemplo n.º 5
0
    def create(cls, **kwargs):
        try:
            db_wrap = DBWrapper.get_solo()
            conn = db_wrap.connection

            try:
                db_wrap.rdb.table_create(cls._table).run(conn)
            except Exception as e:
                print(f" * [-] Table '{cls._table}' is already exist")

            data = db_wrap.rdb.table(cls._table).insert(kwargs).run(conn)
            conn.close()
            obj = cls(**kwargs)
            obj.pk = data['generated_keys'][0]
            return obj

        except:
            print(f" * [-] {cls} object create error error")
Ejemplo n.º 6
0
from db.utils import DBWrapper, establish_connection
from db.models.user import User, Book

from rethinkdb import r

db_wrap = DBWrapper()

db_wrap.setup()

conn = db_wrap.connection
rdb = db_wrap.rdb

print('TABLE', User.table, Book.table)
# print(User.filter(r.row['age'].eq(21), fields=['age', 'name']))