bee.api
Database operation: Suid (select,update,insert,delete),
the null and empty string are not handled by default.
Select the records according to entity and condition.
since 1.6.0
Parameters
- entity: table's entity(do not allow null).
- 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.
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.
Parameters
- entity: table's entity(do not allow null).
The ID field of entity cannot be null and as filter condition.
Returns
the numbers of update records successfully, if fails,return integer less than 0.
According to entity object insert record.
Parameters
- entity: table's entity(do not allow null).
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.
Delete the records according to entity and condition.
since 1.6.0
Parameters
- entity: table's entity(do not allow null).
- 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.
Database operation: Suid (select,update,insert,delete), it supports more parameters than Suid.
The SQL UPDATE statement consists of two parts: set and where. SuidRich specifies one of them
and tries to use the default implementation method for the other.
Therefore, the update method is divided into two parts:
in the updateBy method, string whereFields (if has) can indicate the field used for WHERE in SQL.
When whereFields is specified, fields that are not in whereFields will default.
Convert to the set part of SQL UPDATE statement (null and empty strings are filtered by default).
If the value of an attribute of the same entity is used in the where part, it is meaningless to use it
in the update set part (because their values are the same at this time)
However, it can be set by using the set(String fieldName, Number num) and other methods.
The method set,setMultiply,setAdd,setWithField of condition is processed before processing the where field,
so it is not affected by the specified where condition field
The fields set by the Condition of the updateBy methods will be parsed, which is not affected by the updateFields
parameter and the whereFields parameter.
Just select some fields,and can specify page information.
Parameters
- entity: table's entity(do not allow null).
- 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.
Insert records by batch type.
Parameters
- entity_list: table's entity list(do not allow null).
Returns
the number of inserted record(s) successfully.
select the first record.
Parameters
- entity: table's entity(do not allow null).
Returns
return the first record
Select record by id.
Parameters
- entity_class: table's entity class(do not allow null).
- id: value of entity's id field.
Returns
return one entity which owns this id.
Delete record by id.
Parameters
- entity_class: table's entity class(do not allow null).
- ids: value of entity's id field.
Returns
the number of deleted record(s) successfully,if fails, return integer less than 0.
Select result with one function,Just select one function.
Parameters
- entity: table's entity(do not allow null).
- 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.
total number of statistical records.
Parameters
- entity: table's entity(do not allow null).
Returns
total number of records that satisfy the condition.
Check whether the entity corresponding record exist
Parameters
- entity: table's entity(do not allow null).
Returns
true,if have the record, or return false.
Update record according to whereFields.
Parameters
- entity: table's entity(do not allow null).
Fields that are not specified as whereFields, as part of the set(only non empty and non null fields
are processed by default). - 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.
According to the database table generated by Bean, Bean does not need to configure
too much field information. This method only considers the general situation, and is not
recommended if there are detailed requirements.
Parameters
- entity_class: Class table's entity_class(do not allow null).
- is_drop_exist_table: whether drop the exist table before create
Returns
flag whether create successfully.
create normal index
Parameters
- entity_class: class type of entity.
- fields: the fields of entity.
- index_name: index name
create unique index
Parameters
- entity_class: class type of entity.
- fields: the fields of entity.
- index_name: index name
Support sql string with placeholder.The sql statement is really DB's grammar,not object oriented type.
Support placeholder or #{para} or #{para%} or #{%para} or #{%para%},
can prevent SQL injection attacks through Preparedstatement
If possible, it is recommended to use object-oriented operation methods, such as Suid and SuidRich.
It can use Bee cache to achieve higher query efficiency.
Select record(s) via the placeholder(?) statement.
eg: select * from orders where userid=?
Parameters
- sql: SQL select statement which use placeholder
- return_type_class: class type for return
- params: list type params for placeholder
- start: Start index,min value is 0 or 1(eg: MySQL is 0,Oracle is 1).
- size: Fetch result size (>0).
Returns
list which element type is same as return_type_class.
Select record(s) via the placeholder(?) statement.
eg: select * from orders where userid=?
Parameters
- sql: SQL select statement which use placeholder
- return_type_class: class type for return
- params_dict: dict type params for placeholder
- start: start index, min value is 0 or 1(eg: MySQL is 0,Oracle is 1).
- size: fetch result size (>0).
Returns
list which element type is same as return_type_class.
Modify database records with update, insert or delete statement.
It is not recommended because the framework does not know what table has been changed,
which will affect the correctness of the cache and cause the risk of inaccurate cache data.
Parameters
- sql: SQL statement which use placeholder.
- params: list type params for placeholder.
Returns
the number of affected successfully records.
Modify database records with update, insert or delete statement.
It is not recommended because the framework does not know what table has been changed,
which will affect the correctness of the cache and cause the risk of inaccurate cache data.
Parameters
- sql: SQL statement which use placeholder.
- params_dict: dict type params for placeholder
Returns
the number of affected successfully records.