Please enable JavaScript to view this site.

Knowledge Bridge Documentation

Help version: 3.3.8

Navigation: Self-guided Training > Unit 15: Databases

Creating and Accessing Databases

Scroll Prev Top Next More

 

This topic describes how to use relational databases in kBridge. The methodology is designed as a simple way to import and use relational database information in a kBridge Project.

 

Requisites

External: You will need a database external to kBridge, which must be a relational database created by SQLite (https://www.sqlite.org), a self-contained, embeddable open source SQL database management system. (Training on SQLite is outside the scope of this help file. There are extensive online tutorials and documentation for SQLite.)

 

You then import this database into your kBridge Resources folder. In the future, kBridge will support more database options, including connection to your own on-premises databases.

 

Internal: Within kBridge, you use the SqliteDB Design. This can be used alone or mixed into your Designs and Models. This Design includes a means to connect external databases to your kBridge Project and several methods for accessing data from databases.

 

Creating a Database using the Resources Folder

You use the kBridge Resources folder as the repository for your SQLite data file. See steps 1-3 below to see how to upload SQLite db files to your kBridge Resources folder.

 

Creating a Database with SQLite

Since the database capability in kBridge is currently based on SQLite, we recommend that app"s use as a simple database engine. For greater ease of use, you can employ the add-on DB Browser for SQLite to create simple databases and save them as a .db file.

 

You can either download database examples from the kBridge web site or create your own.

1.Download examples at https://engineeringintent.sharefile.com/d-sabb5ce71f4a4851b

2.Creating your own: save it as TrainingDB.db to use in the following exercises

 

Import the Database as a Resource

Import the database into the Resources folder as follows:

 

1. In the Project Tree, click on Resources. Right-click and select "Import Resource..."

2. In the "Import Resource(s)" dialog, find your .db file on your local machine, then click on Choose.

3. Upload the path name to your database into your Resources folder.

 

JQimportDB

 

IMPORTANT: If you Change a Source Database, Re-Import It

Your imported database is stored in the cloud as an entity that is separate from your original SQLite (source) database. If you change the source, you must re-import the database into kBridge.

 

Access the Database from Rules

To access a database in kBridge, you use a SqliteDb Design, which is part of the BaseLibrary. SqliteDB has two main parameters:

DBFile (required): the link to the database in the Resources folder.

readOnly (optional) Boolean switch that determines whether kBridge should treat the database as read-only (true) or allow writing to the database (false).

 

4. In the Project Tree, under BaseLibrary, click on SqliteDb. Right-click and select "Set as Default."

5. Click on SqliteDb in the Model Tree.

 

Under the Child tab of the SqliteDB model, you will find 2 inputs, DBFile and readOnly:

 

DG-DB-sqliteInputs

 

Obtaining data

SqliteDB has a few Methods for obtaining data from databases including

getRow = get a single row in the database

getRows = get an array of rows

getValue = return the value of a given field in a row

 

KirSqliteRules

 

Each of these methods take standard SQL queries. Training on SQL queries is outside the scope of this help file.

 

Multiple rows are returned as arrays of rows. Rows are represented by JavaScript objects where each column name is a property and the values of each property are the contents of columns in that row.

Knowledge Bridge from Engingeering Intent is a full-featured engineering and sales automation environment