Built-in Functions and Variables
How to use built-in functions and variables
package your.domain;
public interface PersonDao {
void insertPerson( Person person );
}
<mapper namespace="your.domain.PersonDao">
<insert id="insertPerson">
@var kv = ng.kv( ng_args[0], '', true, true );
@var id = ng.id( ng_args[0] );
@var tagName = ng.tagName( ng_args[0] );
INSERT VERTEX `${ tagName }` (
${ ng.join( @kv.columns, ",", "ng.schemaFmt" ) }
)
VALUES ${ id } : (
${ ng.join( @kv.values ) }
);
</insert>
</mapper>
In this example, built-in functions such as
ng.kv
,ng.id
,ng.tagName
,ng.join
,ng.schemaFmt
, and the built-in parameterng_args
are used. After understanding the usage, we will further introduce the functions in the following content.
Built-in Variables
- ng_cm ClassModel Dao interface class model, making it easier to get more class information in the xml (1.1.0-rc)
- ng_mm MethodModel Dao interface method model, making it easier to get method information in the xml, including input parameter types. (1.1.0-rc)
- ng_args The original parameters passed to the Dao interface, before serialization. (1.1.0-rc)
Built-in Functions
- ng.valueFmt
Format data values of uncertain types, ignoring whether to append single quotes and date formatting, and directly pass the original java type
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Value | Object | Y | |
2 | If it is a string, whether to append .* before and after to form a fuzzy query | boolean | N | false |
Starting from v1.1.2, string types are escaped by default, which can be turned off using:
ValueFmtFn.setEscape( false )
- ng.schemaFmt
Add ` before and after the schema name to avoid conflicts with database keywords
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Schema name, such as tagName, edgeName, propertyName | Object | Y |
- ng.tagName
Used to get the tag name from the entity class or Dao interface
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Entity class object corresponding to the Schema | Object | Y | |
2 | Class model, pass in using ng_cm | ClassModel | N | null |
- ng.pkField
Used to get the primary key attribute, java.lang.reflect.Field
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Entity class type | Class<?> | Y | |
2 | If there is no primary key, whether to report an error and interrupt | Boolean | N | false |
- ng.pkName
Used to get the primary key name, String
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Entity class object | Object | Y | |
2 | Use column name when true, use attribute name when false | Boolean | N | true |
- ng.entityType
Used to get the entity class type
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Entity class object | Object | Y |
- ng.fieldNames
Get the attribute name collection (excluding primary key)
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Entity class object | Object | Y | |
2 | Use column name when true, use attribute name when false | Boolean | N | true |
- ng.id
Get the id value
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Entity class object | Object | Y | |
2 | If there is no primary key, whether to report an error and interrupt | Boolean | N | true |
3 | If the value is empty, return a new value generated by the primary key generator when true, return null when false | Boolean | N | true |
- ng.kv
Get multiple collections through the entity object
- columns Column name collection
- valueNames Attribute name collection
- values Value collection
- types Attribute types
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Entity class object | Object | Y | |
2 | Parameter name prefix | String | N | null |
3 | Exclude primary key | Boolean | N | true |
4 | Exclude null values | Boolean | N | true |
5 | If there is no primary key, whether to report an error and interrupt | Boolean | N | true |
- ng.join
Format the collection
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Collection to be formatted | Iterable | Y | |
2 | Separator between elements | String | N | , |
3 | Function name, before each element is concatenated, it can be formatted by the specified formatting function and then concatenated | String | N | null |
- ng.ifStringLike
When the type is a string, prepend and append
.*
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | Value | Object | Y | |
2 | Attribute type | Object | N | null |
3 | Attribute name, used to not write the value in plain text in ngql, but use the parameter name to let nebula take the value from the parameters | String | N | null |
- ng.include
Reference nGQL snippet
Parameter Position | Parameter Description | Type | Required | Default Value |
---|---|---|---|---|
1 | The nGQL snippet ID to be referenced. To reference nGQL snippets from other mappers, add the namespace of the snippet before the snippet ID, e.g., your.domain.TestDao.nGQL-ID | String | Y | |
2 | Additional parameters when referencing nGQL snippets, which will be used preferentially when generating statements | Object | N | null |