# In-Memory Databases

## Overview

In addition to using tables stored on real database servers, Servoy allows you to create **In-Memory** tables (using HSQL). These tables have the same configurations as regular database tables, including column properties and events.

You can populate these In-Memory tables by using a `JSDataSet` and the `createDataSource()` function. This function allows you to dynamically define In-Memory datasources or foundsets at runtime. If you've already defined the In-Memory table in Servoy Developer, you won't need to provide the column and type information again, as this was already defined during design time.

## Creating In-Memory Databases

There are two ways to create an In-Memory database:

1. Using the [Solution Explorer](https://docs.servoy.com/reference/servoy-developer/solution-explorer) context menu under `Datasources -> In Memory -> Create new data source`. This opens a dialog where you can specify the datasource name.

<div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-4c6a266c5931096b21352c89f353b20a64b2e238%2Fcreate-inmem-ds.png?alt=media" alt=""><figcaption><p>Create In-Memory datasource</p></figcaption></figure></div>

After adding the datasource name, the [Table Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/table-editor) will open, allowing you to define the structure of your table, just like any other table.

2. At runtime, using [JSDataSet::createDataSource](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset#createdatasourcename).

This function allows you to dynamically define In-Memory datasources/foundsets at runtime. Alternatively, if you've already defined the In-Memory datasource in the Developer, you won't need to provide column and type information at runtime, as it was set during design time.

## Additional Table Event: onLoad

In-Memory tables have an additional table event called **onLoad**, which is triggered when a form accesses the In-Memory datasource (i.e., when the form's datasource is set to the In-Memory table) or when [datasource.mem.name.getFoundSet()](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset#getFoundSet) is called. This event enables you to populate the In-Memory datasource on demand, rather than during the solution or form's `onLoad` event.

However, you still need to use the [JSDataSet::createDataSource()](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset#createdatasourcename) function within the **onLoad** method to actually populate the In-Memory table.

## Commands Summary

Below is a summary of available commands via the context menu for In-Memory datasources:

| Command                                                     | Summary                                                                                                                    |
| ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| [Create in memory datasource](#create-in-memory-datasource) | Opens the [Table Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/table-editor)                   |
| [Edit table/view](#edit-table-view)                         | Opens the [Table Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/table-editor) to edit the table |
| [Delete In Memory Datasource](#delete-in-memory-datasource) | Deletes the In-Memory Datasource definition                                                                                |
| [Rename In Memory Datasource](#rename-in-memory-datasource) | Renames the In-Memory Datasource definition                                                                                |
| [Search for references](#search-for-references)             | Searches for all locations within the solution where the In-Memory datasource is used                                      |

## Commands Details

### Create in memory datasource

Creates an In-Memory datasource with a specified name (table name). Opens the [Table Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/table-editor) to define and edit the table as you would for a regular database table.

### Edit table/view

Opens the [Table Editor](https://docs.servoy.com/reference/servoy-developer/object-editors/table-editor) to edit the In-Memory table's structure and column information (metadata stored by Servoy Developer).

### Move In Memory Datasource

Moves the In-Memory Datasource to another solution (module).

### Delete In Memory Datasource

Deletes the In-Memory Datasource definition.

### Rename In Memory Datasource

Renames the In-Memory Datasource definition.

### Search for references

Searches for all locations within the solution where the In-Memory datasource is used, and lists them in the ##Search view##. This can be useful to find out which objects are using this data source.
