JSViewDatasource

Overview

A JSViewDataSource provides methods for managing and manipulating view-based data sources in Servoy. It enables the retrieval of column names, creation and management of view foundsets, and dynamic querying capabilities. Methods include obtaining column names through getColumnNames(), fetching the data source string with getDataSource(), and accessing the ViewFoundSet with getFoundSet().

Additionally, getViewFoundSet(query) creates and optionally registers view foundsets from a specified query object. The system retains registered view foundsets in memory until explicitly disposed of using dispose(). The unregister() method facilitates removing view foundsets associated with the datasource, optimizing memory management.

For more details, refer to ViewDataSource Documentation.

Methods Summarized

Type
Name
Summary

Get the column names of a datasource.

Get the datasource string.

Returns the ViewFoundSet that was previously created and registered by a call t o #getViewFoundSet(QBSelect) or #getViewFoundSet(QBSelect,boolean) with the register boolean to true.

Creates a view foundset with the provided query and automatically registers it.

Creates a view foundset with the provided query and the option to register it.

Unregisters a view foundset associated to this view datasource.

Methods Detailed

getColumnNames()

Get the column names of a datasource.

Returns: Array String[] column names

getDataSource()

Get the datasource string.

Returns: String String datasource

Sample

datasources.view.orders.getDataSource() // returns 'view:orders'

getFoundSet()

Returns the ViewFoundSet that was previously created and registered by a call t o #getViewFoundSet(QBSelect) or #getViewFoundSet(QBSelect,boolean) with the register boolean to true. It will return null when it can't find a ViewFoundSet for this datasource.

Returns: JSFoundSet A new ViewFoundSet for the datasource.

Sample

var fs = datasources.view.x.orders.getFoundSet()
var record = fs.getRecord(1)
// changes to records can only be done for ViewFoundSets that also do have the pk selected for the table of the column you change.
record.emp_name = 'John'
fs.save(record);

getViewFoundSet(query)

Creates a view foundset with the provided query and automatically registers it. Registered ViewFoundSets will be kept in memory by the system until ViewFoundSet.dispose() is called.

Parameters

Returns: JSFoundSet the registered view foundset, or null if the datasource columns do not match with the query columns

Sample

var query = datasources.db.example_data.orders.createSelect();
query.result.add(query.columns.shipname);
query.result.add(query.columns.orderid);
query.where.add(query.columns.orderid.le(1280));

var viewfs = datasources.view.a.getViewFoundSet(query);

getViewFoundSet(query, register)

Creates a view foundset with the provided query and the option to register it. A registered ViewFoundSets will be kept in memory by the system until ViewFoundSet.dispose() is called.

Parameters

Returns: JSFoundSet the registered view foundset, or null if the datasource columns do not match with the query columns

Sample

var query = datasources.db.example_data.orders.createSelect();
query.result.add(query.columns.shipname);
query.result.add(query.columns.orderid);
query.where.add(query.columns.orderid.le(1280));

var viewfs = datasources.view.a.getViewFoundSet(query, false);

unregister()

Unregisters a view foundset associated to this view datasource.

Returns: Boolean true if the view foundset was unregistered, false otherwise

Sample

datasources.view.a.unregister();

Last updated