Skip to content
On this page

Built-in Functions and Variables

How to use built-in functions and variables

java
package your.domain;

public interface PersonDao {
  void insertPerson( Person person );
}
xml
<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 parameter ng_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 PositionParameter DescriptionTypeRequiredDefault Value
1ValueObjectY
2If it is a string, whether to append .* before and after to form a fuzzy querybooleanNfalse

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 PositionParameter DescriptionTypeRequiredDefault Value
1Schema name, such as tagName, edgeName, propertyNameObjectY
  • ng.kv

Get multiple collections through the entity object

  • columns Column name collection
  • valueNames Attribute name collection
  • values Value collection
  • types Attribute types
Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Entity class objectObjectY
2Parameter name prefixStringNnull
3Exclude primary keyBooleanNtrue
4Exclude null valuesBooleanNtrue
5If there is no primary key, whether to report an error and interruptBooleanNtrue
  • ng.join

Format the collection

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Collection to be formattedIterableY
2Separator between elementsStringN,
3Function name, before each element is concatenated, it can be formatted by the specified formatting function and then concatenatedStringNnull
  • ng.tagName

Used to get the tag name from the entity class or Dao interface

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Entity class object corresponding to the SchemaObjectY
2Class model, pass in using ng_cmClassModelNnull
  • ng.pkField

Used to get the primary key attribute, java.lang.reflect.Field

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Entity class typeClass<?>Y
2If there is no primary key, whether to report an error and interruptBooleanNfalse
  • ng.pkName

Used to get the primary key name, String

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Entity class objectObjectY
2Use column name when true, use attribute name when falseBooleanNtrue
  • ng.entityType

Used to get the entity class type

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Entity class objectObjectY
  • ng.fieldNames

Get the attribute name collection (excluding primary key)

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Entity class objectObjectY
2Use column name when true, use attribute name when falseBooleanNtrue
  • ng.id

Get the id value

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1Entity class objectObjectY
2If there is no primary key, whether to report an error and interruptBooleanNtrue
3If the value is empty, return a new value generated by the primary key generator when true, return null when falseBooleanNtrue
  • ng.ifStringLike

When the type is a string, prepend and append .*

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1ValueObjectY
2Attribute typeObjectNnull
3Attribute 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 parametersStringNnull
  • ng.include

Reference nGQL snippet

Parameter PositionParameter DescriptionTypeRequiredDefault Value
1The 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
StringY
2Additional parameters when referencing nGQL snippets, which will be used preferentially when generating statementsObjectNnull