# JSTable

## Overview

The `JSTable` represents a database table object used in Servoy, accessible through the maintenance plugin or the `databaseManager`. It provides functionality for interacting with table metadata, columns, and related properties within a database. This object allows developers to retrieve table-specific details such as the SQL name, quoted identifiers, server name, and the table's data source URI.

## Functionality

`JSTable` supports accessing column data, including retrieving names of all columns or primary key columns in a table. Developers can obtain a specific column as a `JSColumn` object or determine if a table is marked as a metadata table. Additionally, table attributes like the SQL name and quoted SQL name can be utilized for database queries or raw SQL operations.

## Methods Summarized

| Type                                                                   | Name                                                          | Summary                                                                                           |
| ---------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [JSColumn](/reference/servoycore/dev-api/database-manager/jscolumn.md) | [getColumn(name)](#getcolumn-name)                            | Returns a JSColumn for the named column (or column dataproviderID).                               |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                 | [getColumnNames()](#getcolumnnames)                           | Returns an array containing the names of all table columns.                                       |
| [String](/reference/servoycore/dev-api/js-lib/string.md)               | [getDataSource()](#getdatasource)                             | Returns the table data source uri.                                                                |
| [String](/reference/servoycore/dev-api/js-lib/string.md)               | [getQuotedSQLName()](#getquotedsqlname)                       | Returns a quoted version of the table name, if necessary, as defined by the actual database used. |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)                 | [getRowIdentifierColumnNames()](#getrowidentifiercolumnnames) | Returns an array containing the names of the identifier (PK) column(s).                           |
| [String](/reference/servoycore/dev-api/js-lib/string.md)               | [getSQLName()](#getsqlname)                                   | Returns the table name as defined in the database.                                                |
| [String](/reference/servoycore/dev-api/js-lib/string.md)               | [getServerName()](#getservername)                             | Returns the Servoy server name.                                                                   |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md)             | [isMetadataTable()](#ismetadatatable)                         | Returns whether table was flagged as metadata table.                                              |

## Methods Detailed

### getColumn(name)

Returns a JSColumn for the named column (or column dataproviderID).

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **name** The name of the column to return the value from.

**Returns:** [JSColumn](/reference/servoycore/dev-api/database-manager/jscolumn.md) JSColumn column.

**Sample**

```js
var jsTable = databaseManager.getTable('udm', 'campaigns')
var jsColumn = jsTable.getColumn('campaign_name')
```

### getColumnNames()

Returns an array containing the names of all table columns.\
If the table is in mem, then the internal rowid column name is not returned.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) String array of column names.

**Sample**

```js
var jsTable = databaseManager.getTable('udm', 'campaigns')
var columnNames = jsTable.getColumnNames()
```

### getDataSource()

Returns the table data source uri.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) String datasource uri.

**Sample**

```js
var jsTable = databaseManager.getTable('udm', 'campaigns')
var dataSource = jsTable.getDataSource()
```

### getQuotedSQLName()

Returns a quoted version of the table name, if necessary, as defined by the actual database used.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) String table name, quoted if needed.

**Sample**

```js
//use with the raw SQL plugin:
//if the table name contains characters that are illegal in sql, the table name will be quoted
var jsTable = databaseManager.getTable('udm', 'campaigns')
var quotedTableName = jsTable.getQuotedSQLName()
plugins.rawSQL.executeSQL('udm',  quotedTableName,  'select * from ' + quotedTableName + ' where is_active = ?', [1])
```

### getRowIdentifierColumnNames()

Returns an array containing the names of the identifier (PK) column(s).\
Please note that if the table is in mem, then the internal rowid column name is also returned.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) String array of row identifier column names.

**Sample**

```js
var jsTable = databaseManager.getTable('udm', 'campaigns')
var identifierColumnNames = jsTable.getRowIdentifierColumnNames()
```

### getSQLName()

Returns the table name as defined in the database.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) String table sql name.

**Sample**

```js
var jsTable = databaseManager.getTable('udm', 'campaigns')
var tableNameForQuery = jsTable.getSQLName()
```

### getServerName()

Returns the Servoy server name.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) String server name.

**Sample**

```js
var jsTable = databaseManager.getTable('udm', 'campaigns')
var serverName = jsTable.getServerName()
```

### isMetadataTable()

Returns whether table was flagged as metadata table.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) boolean is metadata

**Sample**

```js
var jsTable = databaseManager.getTable('udm', 'campaigns')
var isMetaDataTable = jsTable.isMetadataTable()
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jstable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
