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.
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
Sample
getColumnNames()
Get the column names of a datasource.
getDataSource()
Get the datasource string.
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.
Sample
getFoundSet(select)
Parameters
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
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.
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
Sample
getTable()
Get the table of a datasource.
loadRecords(dataSet)
get a new foundset containing records based on a dataset of pks.
Parameters
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
Sample
loadRecords(query)
get a new foundset containing records based on an SQL query string.
Parameters
Sample
loadRecords(query, args)
get a new foundset containing records based on an SQL query string with parameters.
Parameters
Sample
Last updated
Was this helpful?