当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseManager.instance方法代码示例

本文整理汇总了Python中database.DatabaseManager.instance方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.instance方法的具体用法?Python DatabaseManager.instance怎么用?Python DatabaseManager.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在database.DatabaseManager的用法示例。


在下文中一共展示了DatabaseManager.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: all

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
    def all(self):
        db = DatabaseManager.instance(UserManager.DATABASE_NAME)
        results = []

        for data in db.query('SELECT * FROM user;'):
            results.append(User(data['username'], None, bool(data['admin']), data['id'], data['created']))

        return results
开发者ID:silverfernsys,项目名称:sremote,代码行数:10,代码来源:user.py

示例2: update_object

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def update_object(self, obj):
     if obj.id:
         try:
             pwd_hash = pwd_context.encrypt(obj.password)
             db = DatabaseManager.instance(UserManager.DATABASE_NAME)
             db.query(UserManager.UPDATE_OBJECT_QUERY, (obj.username, pwd_hash, int(obj.admin), obj.id,))
         except Exception as e:
             print('Exception: %s' % e)
             raise ValueError('User with id does not exist.')
开发者ID:silverfernsys,项目名称:sremote,代码行数:11,代码来源:user.py

示例3: authenticate

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def authenticate(self, obj, password):
     try:
         db = DatabaseManager.instance(UserManager.DATABASE_NAME)
         data = db.query(UserManager.GET_OBJECT_QUERY, (obj.username,)).nextresult()
         if pwd_context.verify(password, data['password']):
             return True
         else:
             return False
     except:
         return False
开发者ID:silverfernsys,项目名称:sremote,代码行数:12,代码来源:user.py

示例4: get_token_for_user

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def get_token_for_user(self, user):
     if user.id:
         try:
             db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
             query = 'SELECT * FROM token WHERE userid=?;'
             token_data = db.query(query, (user.id,)).nextresult()
             return Token(user=user, token_id=token_data['id'], token=token_data['token'], created=token_data['created'])
         except:
             return None
     else:
         raise ValueError('User has no id.')
开发者ID:silverfernsys,项目名称:sremote,代码行数:13,代码来源:token.py

示例5: delete_object

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def delete_object(self, obj):
     if obj.id:
         db = DatabaseManager.instance(UserManager.DATABASE_NAME)
         db.query(UserManager.DELETE_OBJECT_QUERY, (obj.id,))
         obj.id = None
         obj.created = None
         return True
     else:
         obj.id = None
         obj.created = None
         return False
开发者ID:silverfernsys,项目名称:sremote,代码行数:13,代码来源:user.py

示例6: create_object

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def create_object(self, obj):
     db = DatabaseManager.instance(UserManager.DATABASE_NAME)
     try:
         pwd_hash = pwd_context.encrypt(obj.password)
         db.query(UserManager.CREATE_OBJECT_QUERY, (None, obj.username, pwd_hash, int(obj.admin), time.time(),))
         user_data = db.query(UserManager.GET_OBJECT_QUERY, (obj.username,)).nextresult()
         obj.id = user_data['id']
         obj.created = user_data['created']
     except Exception as e:
         print('Exception: %s' % e)
         raise ValueError('username already exists.')
开发者ID:silverfernsys,项目名称:sremote,代码行数:13,代码来源:user.py

示例7: create_object

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def create_object(self, obj):
     db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
     try:
         if not self.get_token_for_user(obj.user):
             query_data = (None, obj.user.id, obj.token, time.time(),)
             db.query(TokenManager.CREATE_OBJECT_QUERY, params=query_data)
             token_data = db.query(TokenManager.GET_OBJECT_QUERY, (obj.token,)).nextresult()
             obj.id = token_data['id']
             obj.created = token_data['created']
         else:
             raise ValueError('token for this user already exists')
     except ValueError as e:
         raise e
开发者ID:silverfernsys,项目名称:sremote,代码行数:15,代码来源:token.py

示例8: get

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
    def get(self, **kwargs):
        db = DatabaseManager.instance(UserManager.DATABASE_NAME)
        try:
            if 'id' in kwargs and 'username' in kwargs:
                data = db.query('SELECT * FROM user WHERE id=? AND username=?;', (kwargs['id'], kwargs['username'],)).nextresult()
            elif 'id' in kwargs:
                data = db.query('SELECT * FROM user WHERE id=?;', (kwargs['id'],)).nextresult()
            elif 'username' in kwargs:
                data = db.query('SELECT * FROM user WHERE username=?;', (kwargs['username'],)).nextresult()
            else:
                raise ValueError("Missing 'id' or 'username' kwargs.")

            if data:
                return User(data['username'], None, bool(data['admin']), data['id'], data['created'])
            else:
                return None
        except Exception as e:
            return None
开发者ID:silverfernsys,项目名称:sremote,代码行数:20,代码来源:user.py

示例9: all

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
    def all(self):
        join = """
        SELECT user.id AS user_id,
        user.username,
        user.admin,
        user.created AS user_created,
        token.id AS token_id,
        token.token,
        token.created AS token_created
        FROM user INNER JOIN token ON token.userid = user.id ORDER BY user.username, token.created;
        """
        results = []

        db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
        for data in db.query(join):
            user = User(data['username'], None, bool(data['admin']), data['user_id'], data['user_created'])
            token = Token(user, data['token_id'], data['token'], data['token_created'])
            results.append(token)

        return results
开发者ID:silverfernsys,项目名称:sremote,代码行数:22,代码来源:token.py

示例10: get

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def get(self, **kwargs):
     if 'token' in kwargs:
         join = """
         SELECT user.id AS user_id,
         user.username,
         user.admin,
         user.created AS user_created,
         token.id AS token_id,
         token.token,
         token.created AS token_created
         FROM user INNER JOIN token ON token.userid = user.id WHERE token.token=?;
         """
         db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
         try:
             data = db.query(join, (kwargs['token'],)).nextresult()
             user = User(data['username'], None, bool(data['admin']), data['user_id'], data['user_created'])
             token = Token(user, data['token_id'], data['token'], data['token_created'])
             return token
         except:
             return None
     else:
         raise ValueError("Expecting 'token' in arguments.")
开发者ID:silverfernsys,项目名称:sremote,代码行数:24,代码来源:token.py

示例11: delete_object

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def delete_object(self, obj):
     if obj.id:
         db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
         db.query(TokenManager.DELETE_OBJECT_QUERY, (obj.id,))
     obj.id = None
     obj.created = None
开发者ID:silverfernsys,项目名称:sremote,代码行数:8,代码来源:token.py

示例12: drop_table

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def drop_table(self):
     db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
     db.query(TokenManager.DROP_TABLE_QUERY)
开发者ID:silverfernsys,项目名称:sremote,代码行数:5,代码来源:token.py

示例13: create_table

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def create_table(self):
     db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
     if not db.table_exists('token'):
         db.query(TokenManager.CREATE_TABLE_QUERY)
开发者ID:silverfernsys,项目名称:sremote,代码行数:6,代码来源:token.py

示例14: count

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def count(self):
     db = DatabaseManager.instance(TokenManager.DATABASE_NAME)
     return db.query(TokenManager.COUNT_OBJECT_QUERY, params=None, fetchall=False).nextresult()['COUNT(*)']
开发者ID:silverfernsys,项目名称:sremote,代码行数:5,代码来源:token.py

示例15: count

# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import instance [as 别名]
 def count(self):
     db = DatabaseManager.instance(UserManager.DATABASE_NAME)
     return db.query(UserManager.COUNT_OBJECT_QUERY).nextresult()['COUNT(*)']
开发者ID:silverfernsys,项目名称:sremote,代码行数:5,代码来源:user.py


注:本文中的database.DatabaseManager.instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。