get
The get method receives fetch conditions as input and returns a set of records in the rows array (res.data.rows). It works through the cache.
Input Parameters. IAPIQueryParams Interface
columns
columns?: string[]
An array of strings listing the columns that should be in the resulting response. The system will check for the existence of such fields in the profile and will not allow requesting a non-existent field or inserting an SQL expression.
- If not passed, all fields with the
visibleflag set in the Class or Client Object profile will be returned. - as: A field name can be specified using
as, then the result will be returned in a column with the specified name.- Example:
columns: ['user_id as id']. Theuser_idfield will be returned asid. This is useful when a query is formed for use in another query (e.g., inwhereInSelect, which relies onid).
- Example:
where / param_where. Fetch Conditions
By default, there are no conditions (only the default limit is applied).
- A
default_wherecan be defined for a class or client object, which is applied to all queries. whereis an array of condition objects (IOneWhere). A condition can be either a direct comparison (field, type, value) or a group of conditions.
IOneWhere Interface:
export interface IOneWhere {
key?: string,
type?: string
val1?: any
val2?: any
group?: string
comparisonType?: string
is_role?: boolean,
role_group?: string
name?: string // info
isGroup?: boolean // if set, items must be an array
items?: IOneWhere[]
isOr?: boolean // Defines the comparison type with the previous element (OR for the entire group)
binary?: boolean
s?: string // sql string for one where or for all items (if isGroup)
}
Wrapper Functions:
Implemented in \models\system\CoreClass\prepareWhere.ts. They simplify the creation of IOneWhere objects.
whereEq,whereNotEq,whereMore,whereMoreEq,whereLess,whereLessEq: takekeyandval1for standard comparisons (=,!=,>,>=,<,<=).whereBetween: takeskey,val1, andval2. Converted to>=and<=.whereIn,whereNotIn: takeskeyandval1(usually an array). If not an array, redirects towhereEq.whereInSelect,whereNotInSelect: takeskeyandval1(SQL string likeselect id from ...). Used in conjunction withprepareSQL. Blocked for client requests for security reasons.whereLike,whereStartLike,whereEndLike: comparisons likeLIKE(%val1%,val1%,%val1).- Groups:
groupOr,groupAnd. By default, an array of conditions is joined viaAND.groupOrallows joining conditions viaORand wrapping them in parentheses.
Usage Example of Groups:
const res = await r.api(User, 'get', {
where: [
whereEq('gender_sysname', 'MALE'),
groupOr([
whereEq('firstname', 'Alex'),
whereEq('nickname', 'Alex')
])
]
})
if (res.code) return res
const users = res.data.rows
param_where
An obsolete form { [field: string]: any }. The comparison type is always =. Not recommended for use when wrapper functions are available.
limit | page_no | offset
limit?: false | number: AppliesLIMIT. Default is 10000.falsedisables the limit.offset?: number: Offset (default is 0).page_no?: number: If passed,offsetis calculated aspage_no * limit.
sort
sort?: { columns: string[], directions?: string[] } | string | false
Defines the sorting. By default, it’s taken from the Class profile (usually id DESC).
prepareSQL
prepareSQL?: boolean
If true, the query is not executed but returned as an SQL string in res.data.sql. This is a queryBuilder that takes into account core specifics (joins, profiles, data types). Used for subsequent substitution in whereInSelect.
countOnly
countOnly?: boolean
Returns only the number of records for the given conditions (ignoring limit) in res.data.count.
enableInheritValues
enableInheritValues: boolean
For hierarchical entities, allows inheriting values from parents if no value is set (the field must have the is_inherit flag in the profile). An IInheritedValue object is returned instead of the value.
enableMultiValues
enableMultiValues: boolean
For dynamic fields (one-to-many relationship).
false(default): values are returned as a string via the separator"- m | v -"(without quotes or spaces).true: values are returned as an object{ values, valueColumnName }.
co_path___
Passed automatically from client components. Used for the dynamic fields mechanism (e.g., product characteristics depending on the category) so that the core understands the query context and necessary additional fields.
group_by
group_by?: string | string[]
Defines grouping by the specified fields. Usually used together with specColumns.
specColumns
specColumns?: { [alias: string]: string }
Allows specifying SQL expressions or aggregation functions (e.g., sum(amount)).
Important: This parameter is prohibited for client requests.
Output Parameters. IAPIResponse / IError Interface
In case of an error, an instance of MyError or UserError is returned.
Successful response (res.data):
rows: An array of record objects. Typed by automatically created interfaces (e.g.,IDealDataRow).additionalData:count: Number of returned records (respectinglimit).count_all: Total records matching the conditions (ignoringlimit).data_columns: Array of field names in the order defined by the profile.additional_class_fields_profile: Information about inherited fields.cFProfile(server-side only): Profiles of each field of the requested class.