bee.active_record

class BaseMode:

BaseMode for active record type.

eg:

class Orders(BaseMode):
#__tablename__ = "orders"
id:int = None
name:str = None
remark:str = None

def __repr__(self):
    return  str(self.__dict__)

if __name__ == '__main__':
    orders = Orders()
    orderList=orders.select()
def update(self):

According to entity object update record(update record by id).This method just has id field to SQL where expression. table's entity(do not allow null). id is where condition,do not allow null.
The entity corresponding to table and can not be null.
The ID field of entity cannot be null and as filter condition.
The not null and not empty field will update to database except ID.

Returns

the numbers of update records successfully, if fails,return integer less than 0.

def insert(self):

According to entity object insert record. The entity corresponding to table and can not be null.
The not null and not empty field will insert to database.

Returns

the numbers of insert records successfully, if fails,return integer less than 0.

def select(self, condition: bee.condition.Condition = None):

Select the records according to entity and condition.
since 1.6.0

Parameters
  • condition: If the field of entity is not null or empty, it will be translate to field=value.
    Other can define with condition.
Returns

list which contains more than one entity.

def delete(self, condition: bee.condition.Condition = None):

Delete the records according to entity and condition.
since 1.6.0

Parameters
  • condition: If the field of entity is not null or empty, it will be translate to field=value.Other can define with condition.
Returns

the number of deleted record(s) successfully, if fails,return integer less than 0.

def select_paging(self, start, size, *selectFields):

Just select some fields,and can specify page information.

Parameters
  • start: start index,min value is 0 or 1(eg: MySQL is 0,Oracle is 1).
  • size: fetch result size (>0).
  • selectFields: select fields, if more than one,separate with comma in one selectField parameter or use variable parameter.
Returns

list which contains more than one entity.

def select_first(self):

select the first record.

Returns

return the first record

def select_by_id(self, *ids):

Select record by id.

Parameters
  • id: value of entity's id field.
Returns

return one entity which owns this id.

def delete_by_id(self, *ids):

Delete record by id.

Parameters
  • ids: value of entity's id field.
Returns

the number of deleted record(s) successfully,if fails, return integer less than 0.

def select_fun(self, functionType: bee.bee_enum.FunctionType, field_for_fun):

Select result with one function,Just select one function.

Parameters
  • functionType: MAX,MIN,SUM,AVG,COUNT
  • field_for_fun: field for function.
Returns

one function result.

If the result set of statistics is empty,the count return 0,the other return empty string.

def count(self):

total number of statistical records.

Returns

total number of records that satisfy the condition.

def exist(self):

Check whether the entity corresponding record exist

Returns

true,if have the record, or return false.

def updateBy(self, condition: bee.condition.Condition, *whereFields):

Update record according to whereFields.

Parameters
  • condition: Condition as filter the record.
  • whereFields: As a field list of where part in SQL, multiple fields can separated by commas in one
    whereField parameter or use variable parameter (the fields in the list will be used as where filter)
    But if id's value is null can not as filter.
    Notice:the method op of condition also maybe converted to the where expression.
Returns

the numbers of update record(s) successfully,if fails, return integer less than 0.