JSDataSource
Overview
The JSDataSource
represents a data source in the Servoy environment, encompassing both database sources (datasources.db.myserver.mytable
) and in-memory sources (datasources.mem['dsname']
). It provides a comprehensive API for interacting with data, enabling querying, record manipulation, and foundset management.
This class supports creating new foundsets for a data source or retrieving named foundsets based on specific configurations. It allows the execution of queries through query builders (QBSelect
) or raw SQL strings. Records can be loaded dynamically using various input formats, including primary keys, datasets, or queries. The ability to retrieve individual records by primary key ensures precise and efficient data access when needed.
In addition to record management, JSDataSource
facilitates retrieving metadata such as column names and table information for a data source. It supports the creation of query builders, optionally with table aliases, allowing complex query construction and interaction with outer tables in nested SQL scenarios.
Methods Summarized
Create a query builder for a data source.
Create a query builder for a data source with given table alias.
Get the column names of a datasource.
Get the datasource string.
Returns a foundset object for a specified datasource or server and tablename.
Returns a foundset object for a specified pk base query.
An existing foundset under that name will be returned, or created.
Get all currently foundsets for this datasource.
Get a single record from a datasource.
Get the table of a datasource.
get a new foundset containing records based on a dataset of pks.
get a new foundset containing records based on a QBSelect query that is given.
get a new foundset containing records based on an SQL query string.
get a new foundset containing records based on an SQL query string with parameters.
Methods Detailed
createSelect()
Create a query builder for a data source.
Returns: QBSelect query builder
Sample
createSelect(tableAlias)
Create a query builder for a data source with given table alias. The alias can be used inside custom queries to bind to the outer table.
Parameters
String tableAlias the table alias to use
Returns: QBSelect query builder
Sample
getColumnNames()
Get the column names of a datasource.
Returns: Array String[] column names
getDataSource()
Get the datasource string.
Returns: String String datasource
Sample
getFoundSet()
Returns a foundset object for a specified datasource or server and tablename. It is important to note that this is a FACTORY method, it constantly creates new foundsets.
Returns: JSFoundSet A new JSFoundset for the datasource.
Sample
getFoundSet(select)
Parameters
QBSelect select The query to get the JSFoundset for.
Returns: JSFoundSet A new JSFoundset with that query as its base query.
Sample
getFoundSet(name)
An existing foundset under that name will be returned, or created. If there is a definition (there is a form with a named foundset property with that name), the initial sort from that form will be used. If named foundset datasource does not match current datasource will not be returned (will return null instead).
Parameters
String name The named foundset to get for this datasource.
Returns: JSFoundSet An existing named foundset for the datasource.
Sample
getLoadedFoundSets()
Get all currently foundsets for this datasource. </br> This method can be used to loop over foundset and programatically dispose them to clean up resources quickly.
Returns: Array An array of foundsets loaded for this datasource.
Sample
getRecord(pk)
Get a single record from a datasource. For the sake of performance, if more records are needed, don't call this method in a loop but try using other methods instead.
Parameters
Object pk The primary key of the record to be retrieved. Can be an array, in case of a composite pk.
Returns: JSRecord a record
Sample
getTable()
Get the table of a datasource.
Returns: JSTable JSTable table
loadRecords(dataSet)
get a new foundset containing records based on a dataset of pks.
Parameters
JSDataSet dataSet ;
Returns: JSFoundSet a new JSFoundset
Sample
loadRecords(qbSelect)
get a new foundset containing records based on a QBSelect query that is given.
This is just a shotcut for datasources.db.server.table.getFoundset() and then calling loadRecords(qbSelect) on the resulting foundset. So it has the same behavior as JSFoundset.loadRecords(qbselect) that is that the given query is set as a "search" condition on the existing query of the foundset. This means that if you do loadAllRecords() or calling clear() on it the qbselect conditon will also be removed. loadAllRecords() will revert back to the foundsets original query (see #getFoundSet(QBSelect) clear() will revert back to the original foundset query and add a "clear" condition to the query ( resulting in 1 = 2)
Parameters
QBSelect qbSelect a query builder object
Returns: JSFoundSet a new JSFoundset
Sample
loadRecords(query)
get a new foundset containing records based on an SQL query string.
Parameters
String query an SQL query
Returns: JSFoundSet a new JSFoundset
Sample
loadRecords(query, args)
get a new foundset containing records based on an SQL query string with parameters.
Parameters
String query an SQL query string with parameter placeholders
Array args an array of arguments for the query string
Returns: JSFoundSet a new JSFoundset
Sample
Last updated