How is your experience with the OutSystems Community?
clientdb
Reactive icon

ClientDB

Stable version 1.0.0 (Compatible with OutSystems 11)
Uploaded
 on 29 Oct (9 hours ago)
 by 
0.0
 (0 ratings)
clientdb

ClientDB

Documentation
1.0.0

Quick start

  1. Add ClientDB as a dependency of your app (use version 0.1.6 or later).
  2. On your screen's OnReady, check whether your table exists, and create the database only if it doesn't:
    • TableExists(TableName = "contacts")
    • If IsSuccess and Exists are both True → load your data.
    • Otherwise → InitDBWithSchema(DbName = "MyAppDB", SchemaJSON = <schema below>), then insert any seed data.
  3. Read data with GetAll, Query, Search, etc. and use JSONDeserialize on RecordsJSON into a list of your Structure.
  4. Write data with JSONSerialize of a Structure into RecordJSON / RecordsJSON.

Important: InitDBWithSchema deletes and recreates the database every time it runs. Call it only when the table does not exist yet (step 2), otherwise existing data is lost.

Schema format (InitDBWithSchema → SchemaJSON)

An array of tables:

[
{
"name": "contacts",
"keyPath": "Id",
"autoIncrement": true,
"indexes": [ { "name": "Name" }, { "name": "City" } ]
}
]

Index options: name (required), keyPath (defaults to name), unique, multiEntry.

Adding a table later (AddTable → SchemaStr)

Same shape as one table above, without the name (the name comes from TableName):

{ "keyPath": "Id", "autoIncrement": true, "indexes": [ { "name": "Total" } ] }


Inserting records

  • When the table uses autoIncrement, do not send an Id field — the database assigns one and returns it in NewId / NewIdsJSON. Tip: use a separate Structure without Id for inserts.
  • Upsert / UpsertBulk: include the Id to update an existing record, leave it out to insert a new one.

Query inputs

ActionInput format
QueryField + Value (text; numbers are matched too, e.g. "25")
QueryInValuesJSON: ["Paris","Rome"]
QueryMultipleFiltersJSON: {"City":"London","Name":"Ann"} or [{"field":"City","value":"London"}]
QueryRange / DeleteRangeLower / Upper as text. Numeric when both bounds are numbers; empty = no limit on that side
QueryStartsWithField + Prefix
SearchField + Keyword (case-insensitive contains)
GetAllSortedField (an index) + Order = asc or desc
GetPagedPage (starts at 1) + PageSize
Update / UpdateWhereChangesJSON: only the fields to change, e.g. {"City":"Berlin"}
DeleteBulkIdsJSON: [3,7,9]

Transactions (RunTransaction → OperationsJSON)

[
{ "type": "add", "record": { "Name": "Ivy" } },
{ "type": "put", "record": { "Id": 3, "Name": "Cara" } },
{ "type": "delete", "id": 4 }
]

Supported types: add, put (also upsert / update), delete, clear. If any operation fails, none are applied.

Outputs and errors

Every action returns IsSuccess (Boolean) and ErrorMessage (Text). Always check IsSuccess before using the other outputs. Typical messages: "No database is initialized.", "Table does not exist.", invalid JSON, or "Database upgrade is blocked by another open connection…" (close other tabs and retry).