Doc
  • Get Started
  • Academy
  • Library
  • Languages iconEnglish
    • Português

›Resources

Libraries

  • Overview
  • Introduction

Resources & Objects

    Resources

    • App
    • Auth
    • Component
    • Config
    • Convert
    • CORS
    • Cron
    • Crypto
    • CSV
    • DB
    • Env
    • Error
    • Exec
    • Firebase
    • Form
    • Group
    • Header
    • HTML
    • Image
    • IMAP
    • Jasper
    • Jwt
    • Lang
    • Log
    • Monitor
    • OS
    • Out
    • PDF
    • RabbitMQ
    • Random
    • Remote
    • Form
    • Req
    • Res
    • Server
    • Setup
    • SMTP
    • Storage
    • Template
    • Time
    • Uid
    • Url
    • User
    • Val
    • WebSocket
    • XLS
    • XML

    Objects

    • Async
    • CheckExists
    • Column
    • DataItem
    • DataSchema
    • DBBatch
    • DBSearchResult
    • File
    • IMAPConfig
    • Index
    • InputStream
    • OSCommand
    • OutputStream
    • RandomString
    • RemoteResponse
    • Sequence
    • Service
    • SMTPConfig
    • Table
    • Values
    • XLSPosition

App Folders

  • Application folder structure
  • Config
  • DB
  • Public
  • Server
  • Storage
  • UI

DB

Datasource loading resource. This resource allows you to load the datasource that suits you best, supports connection to MariaDB, MSSQLServer, PostgreSQL, H2 and Oracle.

// Be careful when entering parameters in queries,
// you must not use the string concatenation
// to ensure security against SQL Injection as it follows:

const NOK = _db.query(
  'select * from client where id = '+ _req.getString('id')
);

// WARNING: The above example is incorrect.
// Follow the pattern below to ensure safety
// when injecting parameters:

const OK = _db.query(
  'select * from client where id = ?', _val.list().add( _req.getString('id') )
);

all


_db.all(arg0: string) : List

Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( List )


batch


_db.batch() : DBBatch

Description

Starts batch processing of database executions.

How To Use
const batchParameters = _db.batch(`
        insert into product(id, uid, name, price, active)
        values(nextval('product_id'), ?, ?, ?, true)
    `)
    .put(_uid.generate(), "Netuno Batch 1", 3.2)
    .put(_uid.generate(), "Netuno Batch 2", 5.4)
const results = batchParameters.execute()
Return

( DBBatch )

Batch execution manager.


_db.batch(sqlCommand: string) : DBBatch

Description

Starts the batch processing of executions in the database, based on a single command that will be executed multiple times with variation of the data.

How To Use
const batchParameters = _db.batch(`
        insert into product(id, uid, name, price, active)
        values(nextval('product_id'), ?, ?, ?, true)
    `)
    .put(_uid.generate(), "Netuno Batch 1", 3.2)
    .put(_uid.generate(), "Netuno Batch 2", 5.4)
const results = batchParameters.execute()
Attributes
NAMETYPEDESCRIPTION
sqlCommandstringSQL command that will be used as the basis for all interactions.
Return

( DBBatch )

Batch execution manager.


checkExists


_db.checkExists() : CheckExists

Return

( CheckExists )


column


_db.column() : Column

Return

( Column )


config


_db.config() : Values

Description

Gets the connection configuration to the database being used. The connection details are defined in the application environment configuration document, more information in the Multiple Databases tutorial.

How To Use
_header.contentTypePlain()

const db_DEFAULT_Config = _db.getConfig()
_out.print(`The DEFAULT DB connection is: ${db_DEFAULT_Config.toJSON()}\n`)

const db_OTHER_Config = _db.init("countries").getConfig()
_out.print(`The OTHER DB connection is: ${db_OTHER_Config.toJSON()}\n`)

Return

( Values )

Configuration of the connection to the database being used.


date


_db.date() : Date

Description

Gets the current date to be used in database operations.

Return

( Date )

Current date.


_db.date(time: Long) : Date

Description

Through the long number that identifies the exact date, it creates a new Date object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
timeLongLong number for the exact date.
Return

( Date )

New object of type: java.sql.Date


_db.date(text: string) : Date

Description

With the text content you get the date object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
textstringText containing date in the format: yyyy-MM-dd
Return

( Date )

Date obtained from the text.


_db.date(instant: Instant) : Date

Description

Using the Instant object, it creates a new Date object with java.sql.Date.from, to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
instantInstantObject of type: java.time.Instant
Return

( Date )

New object of type: java.util.Date


_db.date(localDateTime: LocalDate) : Date

Description

Using the LocalDateTime object, it creates a new Date object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
localDateTimeLocalDateObject of type: java.time.LocalDateTime
Return

( Date )

New object of type: java.sql.Date


delete


_db.delete(table: string, id: int) : int

Description

Performs the deletion of records in the database based on the ID.

How To Use
// Performs data deletion via ID

const id = 1;

const result = _db.delete(
    "client",
    id
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringTable's name in the database.
idintRecord's ID to be deleted.
Return

( int )

Number of records affected by the deletion.


_db.delete(table: string, uid: string) : int

Description

Performs the deletion of records in the database based on the UID.

How To Use
// Executa a eliminação através do uid

const uid = "1d8722f4-fa28-4a08-8098-6dd5cab1b212";

const result = _db.delete(
    "client",
    uid
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringTable's name in the database.
uidstringRecord's UID to be deleted.
Return

( int )

Number of records affected by the deletion.


_db.delete(table: string, data: Map) : int

Description

Performs the deletion of records in the database based on the ID or UID passed on the data object.

How To Use
// Performs data deletion via ID or UID

const result = _db.delete(
    "client",
    _val.map().set("id", 1)
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringTable name in the database.
dataMapData structure that should be deleted based on your ID or UID.
Return

( int )

Number of records affected by deletion.


_db.delete(table: string, data: Values) : int

Description

Performs the deletion of records in the database based on the ID or UID passed on the data object.

How To Use
// Performs data deletion via ID or UID

const result = _db.delete(
    "client",
    _val.map().set("id", 1)
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringTable name in the database.
dataValuesData structure that should be deleted based on your ID or UID.
Return

( int )

Number of records affected by deletion.


deleteMany


_db.deleteMany(arg0: string, arg1: Object[]) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Object[]
Return

( int[] )


_db.deleteMany(arg0: string, arg1: List) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1List
Return

( int[] )


_db.deleteMany(arg0: string, arg1: Values) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
Return

( int[] )


escape


_db.escape(data: string) : string

Description

It guarantees the encoding to define names in the database, usually quotation marks (").

Attributes
NAMETYPEDESCRIPTION
datastringName that needs to be used in the database, such as table or column name
Return

( string )

Safe name to use in databases, as in tables and columns.


escapeEnd


_db.escapeEnd() : string

Description

Gets the end encoding for defining names in the database, usually quotes (").

Return

( string )

End of names in database.


escapeStart


_db.escapeStart() : string

Description

Gets the start encoding for defining names in the database, usually quotes (").

Return

( string )

Beginning of names in database.


execute


_db.execute(sqlCommand: string) : int

Description

Execute commands directly on the database, commands such as inserts and updates can be executed as required.

How To Use
const rowsAffected = _db.execute(`
    insert into product(id, uid, name, price, active)
    values(nextval('product_id'), '${_uid.generate()}', '${_db.sanitize('Netuno Insert Test 1')}', 3.2, true)
`)
Attributes
NAMETYPEDESCRIPTION
sqlCommandstringSQL command that will be executed directly on the database.
Return

( int )

Number of lines affected by the executed command.


_db.execute(sqlCommand: string, params: Object[]) : int

Description

Execute commands directly on the database, commands such as inserts and updates can be executed as required.

How To Use
const rowsAffected = _db.execute(`
    insert into product(id, uid, name, price, active)
    values(nextval('product_id'), ?, ?, ?, true)
`, _uid.generate(), "Netuno Insert Test 1", 3.2)
Attributes
NAMETYPEDESCRIPTION
sqlCommandstringSQL command that will be executed directly on the database.
paramsObject[]The sequence of parameter values that are injected into the command.
Return

( int )

Number of lines affected by the executed command.


_db.execute(sqlCommand: string, params: List) : int

Description

Execute commands directly on the database, commands such as inserts and updates can be executed as required.

How To Use
const rowsAffected = _db.execute(`
    insert into product(id, uid, name, price, active)
    values(nextval('product_id'), ?, ?, ?, true)
    `, _val.list()
        .add(_uid.generate())
        .add("Netuno Insert Test 1")
        .add(3.2)
)
Attributes
NAMETYPEDESCRIPTION
sqlCommandstringSQL command that will be executed directly on the database.
paramsListList of parameter values that are injected into the command.
Return

( int )

Number of lines affected by the executed command.


_db.execute(sqlCommand: string, params: Values) : int

Description

Execute commands directly on the database, commands such as inserts and updates can be executed as required.

How To Use
const rowsAffected = _db.execute(`
    insert into product(id, uid, name, price, active)
    values(nextval('product_id'), ?, ?, ?, true)
    `, _val.list()
        .add(_uid.generate())
        .add("Netuno Insert Test 1")
        .add(3.2)
)
Attributes
NAMETYPEDESCRIPTION
sqlCommandstringSQL command that will be executed directly on the database.
paramsValuesList of parameter values that are injected into the command.
Return

( int )

Number of lines affected by the executed command.


find


_db.find(table: string, params: Values) : List

Description

From an object that has the structure similar to an SQL query, you get a list of the data found in the search conditions. Build the query compatible with any type of database. Allows conditions, ordering, avoids SQL Injection, among others. Example that demonstrates how to define columns, conditions, ordering and pagination:

How To Use
const list = _db.find(
    "pessoa",
    _val.map()
        .set(
            "columns",
            _val.list()
                .add("uid")
                .add(
                    _val.map()
                        .set("name", "John")
                        .set("surname", "Lennon")
                    )
                .add("email")
        )
        .set(
            "where",
            _val.map()
                .set("grupo", 1)
                .set(
                    "email",
                    _val.map()
                        .set("operator", "like")
                        .set("value", "%@e-mail.sample")
                 )
        )
        .set(
            "order",
            _val.list()
                .add("name")
                .add("surname")
        )
        .set("limit", 10)
        .set("offset", 5)
)
_out.json(
    list
)
Attributes
NAMETYPEDESCRIPTION
tablestringTable name.
paramsValuesQuery definition, supports limiting columns (columns), adding conditions (where), ordering (order), among others.
Return

( List )

List of data records found.


findFirst


_db.findFirst(table: string, params: Values) : Values

Description

From an object that has the structure similar to an SQL query, you get a list of the data found in the search conditions. Build the query compatible with any type of database. Allows conditions, ordering, avoids SQL Injection, among others. Example that demonstrates how to define columns, conditions, ordering and pagination:

How To Use
const record = _db.findFirst(
    "pessoa",
    _val.map()
        .set(
            "where",
            _val.map()
                .set("email", "pessoa@e-mail.exemplo")
        )
)
_out.json(
    record
)
Attributes
NAMETYPEDESCRIPTION
tablestringTable name.
paramsValuesQuery definition, supports limiting columns (columns), adding conditions (where), ordering (order), among others.
Return

( Values )

Record line data found.


findQuery


_db.findQuery(arg0: string, arg1: Values) : string

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
Return

( string )


get


_db.get(table: string, id: int) : Values

Description

Obtains the record data from the database through the name of the table and the ID.

How To Use
// All registry data with the given ID.

const dbClientRecord = _db.get(
    "client",
    100
)

_out.json(dbClientRecord);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table in the database that should obtain the data.
idintRecord ID that should get the data.
Return

( Values )

The item data found or null if it does not exist.


_db.get(table: string, uid: string) : Values

Description

Obtains the record data from the database through the name of the table and the UID.

How To Use
// All registry data with the given UID.

const dbClientRecord = _db.get(
    "client",
    "cbe8bd5a-98c9-48b2-bbac-6a11ac46f2a8"
)

_out.json(dbClientRecord);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table in the database that should obtain the data.
uidstringRecord UID that should get the data.
Return

( Values )

The item data found or null if it does not exist.


getConfig


_db.getConfig() : Values

Description

Gets the connection configuration to the database being used. The connection details are defined in the application environment configuration document, more information in the Multiple Databases tutorial.

How To Use
_header.contentTypePlain()

const db_DEFAULT_Config = _db.getConfig()
_out.print(`The DEFAULT DB connection is: ${db_DEFAULT_Config.toJSON()}\n`)

const db_OTHER_Config = _db.init("countries").getConfig()
_out.print(`The OTHER DB connection is: ${db_OTHER_Config.toJSON()}\n`)

Return

( Values )

Configuration of the connection to the database being used.


getKey


_db.getKey() : string

Description

Gets the name of the database connection configuration being used. The connection details must be defined in the application environment configuration document, more information in the Multiple Databases tutorial.

How To Use
_header.contentTypePlain()

const db_DEFAULT_ConnectionName = _db.getKey()
_out.print(`The DEFAULT DB connection is: ${db_DEFAULT_ConnectionName}\n`)

const db_OTHER_ConnectionName = _db.init("countries").getKey()
_out.print(`The OTHER DB connection is: ${db_OTHER_ConnectionName}\n`)

Return

( string )

Name of the connection configuration to the database being used.


index


_db.index() : Index

Return

( Index )


init


_db.init(key: string) : DB

Description

Starts a new DB resource for the connection name that is passed. The connection details must be defined in the application's environment configuration document, more information in the Multiple Databases tutorial.

How To Use
// Run a query in another database                                                                                              

const dbCountries = _db.init('countries')

const countries = dbCountries.query('select code, name from country')

_out.json(countries)
Attributes
NAMETYPEDESCRIPTION
keystringBase connection name defined in the application's environment configurations.
Return

( DB )

The new database feature that uses another database.


insert


_db.insert(table: string, data: Map) : int

Description

Executes the insertion of new data in the database and returns the id of the same.

How To Use
// Executes the insertion of new record and returns the ID

const id = _db.insert(
    "client",
    _val.map()
        .set("name", "Sitana"),
        .set("mail", "admin@sitana.pt")
);

_out.json(
    _val.map().set("id", id)
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table in the database that should receive the data to be entered.
dataMapObject with the data structure to be inserted.
Return

( int )


_db.insert(table: string, data: Values) : int

Description

Executes the insertion of new data in the database and returns the id of the same.

How To Use
// Executes the insertion of new record and returns the ID

const id = _db.insert(
    "client",
    _val.map()
        .set("name", "Sitana"),
        .set("mail", "admin@sitana.pt")
);

_out.json(
    _val.map().set("id", id)
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table in the database that should receive the data to be entered.
dataValuesObject with the data structure to be inserted.
Return

( int )


insertIfNotExists


_db.insertIfNotExists(arg0: string, arg1: Map) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Map
Return

( int )


_db.insertIfNotExists(arg0: string, arg1: Values) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
Return

( int )


insertMany


_db.insertMany(arg0: string, arg1: Object[]) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Object[]
Return

( int[] )


_db.insertMany(arg0: string, arg1: List) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1List
Return

( int[] )


_db.insertMany(arg0: string, arg1: Values) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
Return

( int[] )


isH2


_db.isH2() : boolean

Description

Checks whether the connected database is H2 Database.

Return

( boolean )

If it is H2 Database.


isH2DataBase


_db.isH2DataBase() : boolean

Description

Checks whether the connected database is H2 Database.

Return

( boolean )

If it is H2 Database.


isMariaDB


_db.isMariaDB() : boolean

Description

Checks whether the connected database is MariaDB.

Return

( boolean )

If it is MariaDB.


isPG


_db.isPG() : boolean

Description

Checks whether the connected database is PostgreSQL.

Return

( boolean )

If it is PostgreSQL.


isPostgreSQL


_db.isPostgreSQL() : boolean

Description

Checks whether the connected database is PostgreSQL.

Return

( boolean )

If it is PostgreSQL.


key


_db.key() : string

Description

Gets the name of the database connection configuration being used. The connection details must be defined in the application environment configuration document, more information in the Multiple Databases tutorial.

How To Use
_header.contentTypePlain()

const db_DEFAULT_ConnectionName = _db.getKey()
_out.print(`The DEFAULT DB connection is: ${db_DEFAULT_ConnectionName}\n`)

const db_OTHER_ConnectionName = _db.init("countries").getKey()
_out.print(`The OTHER DB connection is: ${db_OTHER_ConnectionName}\n`)

Return

( string )

Name of the connection configuration to the database being used.


query


_db.query(arg0: string) : List

Description

Run a SQL query directly on the database. Be very careful with SQL Injection.

How To Use
const safeMaxAmount = _db.toFloat(_req.getString("max_amount"))

_out.json(
    _db.query(`
        select * from product
        where price < ${safeMaxAmount}
    `)
)
Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( List )

List of data obtained with the direct query to the database.


_db.query(query: string, params: Object[]) : List

Description

Run a SQL query directly on the database. Be very careful with SQL Injection.

How To Use
_out.json(
    _db.query(`
        select * from product
        where price < ?
    `, _req.getString("max_price"))
)
Attributes
NAMETYPEDESCRIPTION
querystringCommand that will be executed on the database to get records.
paramsObject[]List of parameter values that will be injected into the database query.
Return

( List )

List of data obtained with the direct query to the database.


_db.query(query: string, params: List) : List

Description

Run a SQL query directly on the database. Be very careful with SQL Injection.

How To Use
_out.json(
    _db.query(`
        select * from product
        where price < ?
    `, _req.getString("max_price"))
)
Attributes
NAMETYPEDESCRIPTION
querystringCommand that will be executed on the database to get records.
paramsListList of parameter values that will be injected into the database query.
Return

( List )

List of data obtained with the direct query to the database.


_db.query(query: string, params: Values) : List

Description

Run a SQL query directly on the database. Be very careful with SQL Injection.

How To Use
_out.json(
    _db.query(`
        select * from product
        where price < ?
    `, _req.getString("max_price"))
)
Attributes
NAMETYPEDESCRIPTION
querystringCommand that will be executed on the database to get records.
paramsValuesList of parameter values that will be injected into the database query.
Return

( List )

List of data obtained with the direct query to the database.


queryFirst


_db.queryFirst(query: string) : Values

Description

Run an SQL query directly on the database and get only the first record. Be very careful with SQL Injection.

How To Use
const productFound = _db.queryFirst(`
    select * from product
    where name like '%${_db.sanitize(_req.getString('term'))}%'
`)
_log.info('The first product found:', productFound)
Attributes
NAMETYPEDESCRIPTION
querystringCommand that will be executed on the database to get the record.
Return

( Values )

The first data record obtained with the direct database query.


_db.queryFirst(query: string, params: Object[]) : Values

Description

Run an SQL query directly on the database and get only the first record. Be very careful with SQL Injection.

How To Use
const productFound = _db.queryFirst(`
    select * from product
    where name like ?
`, `%${_req.getString('term')}%`)
_log.info('The first product found:', productFound)
Attributes
NAMETYPEDESCRIPTION
querystringCommand that will be executed on the database to get the record.
paramsObject[]List of parameter values that will be injected into the database query.
Return

( Values )

The first data record obtained with the direct database query.


_db.queryFirst(query: string, params: List) : Values

Description

Run an SQL query directly on the database and get only the first record. Be very careful with SQL Injection.

How To Use
const productFound = _db.queryFirst(`
    select * from product
    where name like ?
`, `%${_req.getString('term')}%`)
_log.info('The first product found:', productFound)
Attributes
NAMETYPEDESCRIPTION
querystringCommand that will be executed on the database to get the record.
paramsListList of parameter values that will be injected into the database query.
Return

( Values )

The first data record obtained with the direct database query.


_db.queryFirst(query: string, params: Values) : Values

Description

Run an SQL query directly on the database and get only the first record. Be very careful with SQL Injection.

How To Use
const productFound = _db.queryFirst(`
    select * from product
    where name like ?
`, `%${_req.getString('term')}%`)
_log.info('The first product found:', productFound)
Attributes
NAMETYPEDESCRIPTION
querystringCommand that will be executed on the database to get the record.
paramsValuesList of parameter values that will be injected into the database query.
Return

( Values )

The first data record obtained with the direct database query.


sanitize


_db.sanitize(data: string) : string

Description

It certifies that the content is safe to inject in a direct query to the database, prevents SQL Injection attacks.

Attributes
NAMETYPEDESCRIPTION
datastringInformation that needs to be used in a SQL Injection risk database.
Return

( string )

Safe content to use directly in queries.


sanitizeBoolean


_db.sanitizeBoolean(data: string) : string

Description

It certifies that the content is safe to inject as boolean (true or false) in a direct query to the database, preventing SQL Injection attacks.

Attributes
NAMETYPEDESCRIPTION
datastringInformation that needs to be used as boolean (true or false) in a database with the risk of SQL Injection.
Return

( string )

Content like Boolean (true or false) safe to use directly in queries.


sanitizeFloat


_db.sanitizeFloat(data: string) : string

Description

It certifies that the content is safe to inject as a decimal number in a direct query to the database, prevents SQL Injection attacks.

Attributes
NAMETYPEDESCRIPTION
datastringInformation that needs to be used as a decimal number in a database with risk of SQL Injection.
Return

( string )

Content as a safe decimal number to use directly in queries.


sanitizeInt


_db.sanitizeInt(data: string) : string

Description

It certifies that the content is safe to inject as an integer in a direct query to the database, prevents SQL Injection attacks.

Attributes
NAMETYPEDESCRIPTION
datastringInformation that needs to be used as an integer in a database with risk of SQL Injection.
Return

( string )

Content as a safe integer to use directly in queries.


sanitizeName


_db.sanitizeName(data: string) : string

Description

It certifies that the content is safe to inject as a table or column name in a direct query to the database, preventing SQL Injection attacks.

Attributes
NAMETYPEDESCRIPTION
datastringInformation that needs to be used as a table or column name in a database with the risk of SQL Injection.
Return

( string )

Content such as table or column name safe to use directly in queries.


sanitizePath


_db.sanitizePath(data: string) : string

Description

It certifies that the content is safe to inject as a table name path followed by a period and then the column name (table.column), in direct query to the database, prevents SQL Injection attacks.

Attributes
NAMETYPEDESCRIPTION
datastringInformation that needs to be used as a path (table.name) in a database with the risk of SQL Injection.
Return

( string )

Content as a safe path (table.name) to use directly in queries.


save


_db.save(arg0: string, arg1: int, arg2: Map) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1int
arg2Map
Return

( int )


_db.save(arg0: string, arg1: int, arg2: Values) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1int
arg2Values
Return

( int )


_db.save(arg0: string, arg1: string, arg2: Map) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1string
arg2Map
Return

( int )


_db.save(arg0: string, arg1: string, arg2: Values) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1string
arg2Values
Return

( int )


search


_db.search(arg0: string, arg1: Map) : DBSearchResult

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Map
Return

( DBSearchResult )


_db.search(arg0: string, arg1: Map, arg2: boolean) : DBSearchResult

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Map
arg2boolean
Return

( DBSearchResult )


_db.search(arg0: string, arg1: Values) : DBSearchResult

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
Return

( DBSearchResult )


_db.search(arg0: string, arg1: Values, arg2: boolean) : DBSearchResult

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
arg2boolean
Return

( DBSearchResult )


sequence


_db.sequence() : Sequence

Return

( Sequence )


store


_db.store(arg0: string, arg1: Map) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Map
Return

( int )


_db.store(arg0: string, arg1: Values) : int

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
Return

( int )


table


_db.table() : Table

Return

( Table )


time


_db.time() : Time

Description

Gets the current time to be used in database operations.

Return

( Time )

Current time.


_db.time(time: Long) : Time

Description

Through the long number that identifies the exact time, it creates a new Time object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
timeLongLong number referring to the exact time.
Return

( Time )

New object of type: java.sql.Time


_db.time(text: string) : Time

Description

With the text content you get the time object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
textstringText containing time in the format: HH:mm:ss
Return

( Time )

Time obtained from the text.


_db.time(instant: Instant) : Date

Description

Using the Instant object, it creates a new Date object with java.sql.Time.from, to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
instantInstantObject of type: java.time.Instant
Return

( Date )

New object of type: java.util.Date


_db.time(localDateTime: LocalTime) : Time

Description

Using the LocalDateTime object, it creates a new Time object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
localDateTimeLocalTimeObject of type: java.time.LocalDateTime
Return

( Time )

New object of type: java.sql.Time


timestamp


_db.timestamp() : Timestamp

Description

Gets the current date and time to be used in database operations.

Return

( Timestamp )

Current date and time.


_db.timestamp(time: Long) : Timestamp

Description

Through the long number that identifies the exact time, it creates a new Timestamp object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
timeLongLong number referring to the exact time.
Return

( Timestamp )

New object of type: java.sql.Timestamp


_db.timestamp(text: string) : Timestamp

Description

With the text content you get the date and time object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
textstringText containing date and time in the format: yyyy-MM-dd HH:mm:ss
Return

( Timestamp )

Date and time obtained from the text.


_db.timestamp(instant: Instant) : Timestamp

Description

Using the Instant object, it creates a new Timestamp object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
instantInstantObject of type: java.time.Instant
Return

( Timestamp )

New object of type: java.sql.Timestamp


_db.timestamp(localDateTime: LocalDateTime) : Timestamp

Description

Using the LocalDateTime object, it creates a new Timestamp object to be used in database operations.

Attributes
NAMETYPEDESCRIPTION
localDateTimeLocalDateTimeObject of type: java.time.LocalDateTime
Return

( Timestamp )

New object of type: java.sql.Timestamp


toFloat


_db.toFloat(arg0: string) : string

Description

Ensures that it is a valid number with decimal places to be used directly in a query avoiding SQL Injection.

How To Use
const safeMaxAmount = _db.toFloat(_req.getString("max_amount"))

_out.json(
    _db.query(`
        select * from product
        where price < ${safeMaxAmount}
    `)
)
Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( string )

Content that is safe to use directly in query as a number with decimal places (float).


toInt


_db.toInt(arg0: string) : string

Description

Ensures that it is a valid integer to be used directly in a query avoiding SQL Injection.

How To Use
const safeID = _db.toInt(_req.getString("id"))

_out.json(
    _db.query(`
        select * from client
        where id = ${safeID}
    `)
)
Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( string )

Content that is safe to use directly in query as number/integer.


toIntSequence


_db.toIntSequence(arg0: string) : string

Description

It ensures that it is a sequence of numbers separated by commas to be used directly in a query avoiding SQL Injection.

How To Use
// Ensures that the sequence of IDs looks something like:// 3,5,600,1000
const safeIDs = _db.toIntSequence(_req.getString("ids"))

_out.json(
    _db.query(`
        select * from client
        where id in (${safeIDs})
    `)
)
Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( string )

Sequential numeric content that is safe to use directly in query.


toRawName


_db.toRawName(arg0: string) : string

Description

It certifies that the content passed is a valid name to be used in direct queries to the database, if it is not then an error is returned. For example valid if the name is in the format to be a name of table_name or ofcolumn_name.

Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( string )

Returns the name that is safe to use directly in queries.


toRawPath


_db.toRawPath(arg0: string) : string

Description

It certifies that the content passed is a valid path to be used in direct queries to the database, if it is not then an error is returned. For example, valid if the path is compatible with table_name.column_name.

Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( string )

Returns the path that is safe to use directly in queries.


toString


_db.toString() : string

Description

Ensures that it is a valid string to be used directly in a query avoiding SQL Injection.

How To Use
// Avoid SQL Injection                                                                                                          

const safeName = _db.toString(_req.getString('name'))

_out.json(
    _db.query(`                                                                                                                 
        select * from client                                                                                                    
        where name = '${safeName}'                                                                                              
    `)
)
Return

( string )

Content that is safe to use directly in query as string/varchar/text.


_db.toString(arg0: string) : string

Description

Ensures that it is a valid string to be used directly in a query avoiding SQL Injection.

How To Use
// Avoid SQL Injection                                                                                                          

const safeName = _db.toString(_req.getString('name'))

_out.json(
    _db.query(`                                                                                                                 
        select * from client                                                                                                    
        where name = '${safeName}'                                                                                              
    `)
)
Attributes
NAMETYPEDESCRIPTION
arg0string
Return

( string )

Content that is safe to use directly in query as string/varchar/text.


update


_db.update(table: string, id: int, data: Map) : int

Description

Performs the update of existing data according to the id that comes in the data that is passed.

How To Use
var result = _db.update(
    "client",
    1, // ID of the registry that will be affected.
    _val.map()
        .set("name", "Sitana")
        .set("mail", "admin@sitana.pt")
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table containing the records that must be updated.
idintID of the registry that will be affected by the update.
dataMapObject with the data structure that is to be maintained.
Return

( int )

Number of records affected by the update.


_db.update(table: string, uid: int, data: Values) : int

Description

Performs the update of existing data according to the id that comes in the data that is passed.

How To Use
var uid = "98502cff-d1e1-4efc-8efe-840320925316";

var result = _db.update(
    "client",
    uid,
    _val.map()
        .set("name", "nome")
        .set("mail", "mail@netuno.org")
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table containing the records that must be updated.
uidintUID of the record that will be affected by the update.
dataValuesObject with data structure that should be maintained.
Return

( int )

Number of records affected by the update.


_db.update(table: string, uid: string, data: Map) : int

Description

Performs the update of existing data according to the id that comes in the data that is passed.

How To Use
var uid = "98502cff-d1e1-4efc-8efe-840320925316";

var result = _db.update(
    "client",
    uid,
    _val.map()
        .set("name", "nome")
        .set("mail", "mail@netuno.org")
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table containing the records that must be updated.
uidstringUID of the record that will be affected by the update.
dataMapObject with data structure that should be maintained.
Return

( int )

Number of records affected by the update.


_db.update(table: string, uid: string, data: Values) : int

Description

Performs the update of existing data according to the id that comes in the data that is passed.

How To Use
var uid = "98502cff-d1e1-4efc-8efe-840320925316";

var result = _db.update(
    "client",
    uid,
    _val.map()
        .set("name", "nome")
        .set("mail", "mail@netuno.org")
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table containing the records that must be updated.
uidstringUID of the record that will be affected by the update.
dataValuesObject with data structure that should be maintained.
Return

( int )

Number of records affected by the update.


_db.update(table: string, data: Map) : int

Description

Performs the update of existing data according to the id that comes in the data that is passed.

How To Use
var result = _db.update(
    "client",
    _val.map()
        .set("id", 1)
        .set("name", "Sitana")
        .set("mail", "admin@sitana.pt")
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table containing the records that must be updated.
dataMapObject with the data structure that is to be maintained.
Return

( int )

Number of records affected by the update.


_db.update(table: string, data: Values) : int

Description

Performs the update of existing data according to the id that comes in the data that is passed.

How To Use
var result = _db.update(
    "client",
    _val.map()
        .set("id", 1)
        .set("name", "Sitana")
        .set("mail", "admin@sitana.pt")
);

_out.json(
    "result": result
);
Attributes
NAMETYPEDESCRIPTION
tablestringName of the table containing the records that must be updated.
dataValuesObject with the data structure that is to be maintained.
Return

( int )

Number of records affected by the update.


updateMany


_db.updateMany(arg0: string, arg1: Object[]) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Object[]
Return

( int[] )


_db.updateMany(arg0: string, arg1: List) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1List
Return

( int[] )


_db.updateMany(arg0: string, arg1: Values) : int[]

Attributes
NAMETYPEDESCRIPTION
arg0string
arg1Values
Return

( int[] )


← CSVEnv →
  • all
  • batch
  • checkExists
  • column
  • config
  • date
  • delete
  • deleteMany
  • escape
  • escapeEnd
  • escapeStart
  • execute
  • find
  • findFirst
  • findQuery
  • get
  • getConfig
  • getKey
  • index
  • init
  • insert
  • insertIfNotExists
  • insertMany
  • isH2
  • isH2DataBase
  • isMariaDB
  • isPG
  • isPostgreSQL
  • key
  • query
  • queryFirst
  • sanitize
  • sanitizeBoolean
  • sanitizeFloat
  • sanitizeInt
  • sanitizeName
  • sanitizePath
  • save
  • search
  • sequence
  • store
  • table
  • time
  • timestamp
  • toFloat
  • toInt
  • toIntSequence
  • toRawName
  • toRawPath
  • toString
  • update
  • updateMany

Open Source

Download

admin@netuno.org

support@netuno.org

Copyright © Sitana 2023