Database

◷ Reading Time: 2 minutes

At the expression level as well as Flow level the data can be retrieved from a database.

database

Creates a connection reference to a database

 database (type, cnn)
  • type: Specifies the type of database: MsAccess, MsSql, Oracle, Odbc
  • cnn: Provides connection string to the database

Example:

db = database('mssql','Data Source=.\\SqlExpress;Initial Catalog=Car-Insurance;User ID=sa;Password=123;MultipleActiveResultSets=True')

query

A monad operator that executes a SELECT query against a database reference.

database .query (query, args)

Example 1: Query with array of values as parameter

db.query('select * from HighRiskCars where id in @ids', {ids:[1,2,3]})

Example 2: Query with specifying an Id of record

db.query('select * from HighRiskCars where id=@id', {id:1002})

Example 3: Query with no parameter

db.query('select * from HighRiskCars')

queryExecute

A monad operator that executes one or more INSERT, UPDATE and DELETE query against a database reference.

database .queryExecute (query, args)

Returns: the database, which allows multiple of queryExecute

Example 1: Query with array of values as parameter

db.queryExecute("INSERT INTO testtbl (id, message) VALUES (@id, @message)", {id:custId, message:custMessage})

queryScalar

A monad operator that executes a query against a database reference and returns a value.

database .queryScalar (query, args)

Returns: The value from the first column of the first row of the query.

Updated on February 10, 2020

Was this article helpful?

Related Articles