# Getting started

DataFlow is an internal tool builder. You can build your internal tools fast and simply in less than five minutes.

## 1. Create a workspace.

The workspace is a space where we store apps and projects, every team should have a workspace to separate the work. You can create a new workspace by clicking the + button at the top right of the left sidebar.<br>

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FAtUKsGmwvPyzrkMjyxgm%2Fnew-workspace.png?alt=media&amp;token=da59d271-931d-4553-813b-a82812faac5b" alt=""><figcaption><p>new workspace</p></figcaption></figure>

## 2. Create a project.

The project is where you create, design, and publish your apps.

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FUR7SDZfF3BUM5lNpuAhp%2Fnew-project.png?alt=media&amp;token=3f2e6535-9605-46dd-8b45-33f046012fd5" alt=""><figcaption><p>new project</p></figcaption></figure>

## 3. Create a board and design an app.

Now we can create a board. Boards are a single page where you can lay out components.  After creating the aboard, let's add a button and an input into a board.

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FC7fhCf0KGuplRXPoN9AS%2Fbutton-input.png?alt=media&amp;token=d197b72d-59a5-4b38-865b-8aa770e406b8" alt=""><figcaption><p>create a button and an input</p></figcaption></figure>

## 4. Add an adapter.

Adapters are the backbone of the components. It handles events, queries and modifies component attributes at runtimes. \
\ <br>

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FJi5S4v51WZV6tCRaDXUK%2Fcreate-adatper.png?alt=media&amp;token=b27713d0-1088-4029-83d8-8cbb7978f4c1" alt=""><figcaption><p>create an adapter</p></figcaption></figure>

After creating an adapter, we can add a script that controls the UI components.

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2F6Jax7NYZo382SGSK1gOC%2Fwrite-event.png?alt=media&amp;token=57b03ac6-175f-406c-ad0b-8034865dcf45" alt=""><figcaption><p>write adapter script</p></figcaption></figure>

## 5. Connect a component to an adapter.

We can connect a UI component to an adapter to handle its events. For example, we can connect the button click event to the adapter we just created in the step above.

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FjRuMbm1HFrSIsmPB0c3n%2Fsetup-event.png?alt=media&amp;token=75866178-b76f-4434-ac6f-6de3a81bcfa6" alt=""><figcaption></figcaption></figure>

## 6. Build test and publish.

After settings up, click the Build button (the triangle button on the toolbar) and check out the result.

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FD0jlT1PFfGKnBD4Yalwa%2FCleanShot%202022-12-04%20at%2010.26.56%402x.png?alt=media&amp;token=35e99bdc-1a4b-4fcb-9abd-25e514e11f40" alt=""><figcaption><p>build test</p></figcaption></figure>

Click the home button on the header tab, and you will see the publish button. Click that button to publish the app.

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FFOpTDZoiWlS8N5nSjLLP%2FCleanShot%202022-12-04%20at%2010.29.57%402x.png?alt=media&amp;token=c46ab1de-81d6-48ac-bcd4-ce738f12fc0a" alt=""><figcaption></figcaption></figure>


# 1. UI Components

The UI Components can be used for designing apps. Each component has a unique name, the name is used for data binding (the reference to the object in scripting).<br>

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FNRrhKPzmbj8JID7mQna1%2Flink.png?alt=media&amp;token=de325010-f51a-4c73-aedb-f7fbddea232f" alt=""><figcaption><p>inspector</p></figcaption></figure>

There are a few built-in component objects.

\
1\. Container components: **container, tab view, split view.**

2\. Input components: **button, input field, checkbox, selection dropdown, text area.**

3\. Basic components: **chart, data table, label.**\
\
The UI Components may have event triggers that can be linked to an adapter.<br>

## 1. Attributes

### **name**

The `name` attribute is used for data binding -  the reference to the object at runtime. We can get/set the object label, value, or trigger events using the name\
\
For example a component with the name my\_input: my\_input.label, my\_input.value, my\_input.click()

### label

The `label` attribute is used for displaying the label of the component.

## 2. Frame and Auto Layout

### **Frame**

The frame represents the location and size of the object on the app canvas. The frame includes origin and size. The origin contains the x-axis and the y-axis which tell the location of the object. The size contains width and height which are the width and height of the object.

### **Auto Layout**

Auto layout is how the object responds when the container size change. There are anchors and sizings.\
\
The anchors can be one or all of the values: top, left, bottom, or right.

The sizing can be one or all of the values: width, and height.

You can config and see how it works using the inspector.<br>

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FXRZfMzp6mTs4OkTn43Gl%2FCleanShot%202022-12-04%20at%2014.35.58%402x.png?alt=media&amp;token=864615c9-7eef-4d53-96da-aafdc80571a6" alt=""><figcaption><p>auto layout</p></figcaption></figure>

## 3. Events

Each object has its own events, we can set up the event to link with an adapter.

{% hint style="success" %}
You must create a [JavaScript Runner adapter](/2.-adapters) to handle events.
{% endhint %}

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FivbdiRqIWSB5WGxcwNG6%2FCleanShot%202022-12-04%20at%2014.40.13%402x.png?alt=media&amp;token=45f98c8f-33d0-4711-a556-cc244a1ae620" alt=""><figcaption></figcaption></figure>


# 2. Adapters

Adapters are the backbone of the UI Components.\
\
**1. SQL Runner Adapter**

The SQL Runner Adapter holds the connection to a database, we can run an SQL Query by calling the execAsync function.\
\
execAsync(query: string) -> Promise\<result>  run an SQL and receive the result.

{% hint style="success" %}
How to use SQL Runner?

We can use it in the script of JavaScript Runner to perform a query. For example, we can write a script to run a query and get the result to render.\
\
sql\_runner.execAsync("select 1").then((result)=>{

&#x20;   data\_table.value = result;\
})
{% endhint %}

\
**2. JavaScript Runner Adapter.**\
\
The JavaScript Runner Adapter can be linked with UI components to handle its events.

{% hint style="success" %}
The JavaScript Runner can only run JavaScript. It's an isolation context, there are a few built-in functions:

* alert(string): show an alert dialog.
* prompt(string): show a dialog with input.
* confirm(string): show a confirmation dialog.

You can also access all the UI component objects in the script referenced by their names.
{% endhint %}


# 3. Environments and resources

We can create an environment for resources. Each environment holds a set of configs for resources.

## 1. Create and manage resources

Database resource is a connection to databases. DataFlow supports various database drivers, such as PostgreSQL, MySQL...\
\
Click the Environment dropdown on the header bar to create and manage resources.<br>

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2Fz7uBl1cK1QAwNbXreacw%2FCleanShot%202022-12-04%20at%2011.34.15%402x.png?alt=media&amp;token=640cbcde-ff1a-4f30-84c3-1a77335becbe" alt=""><figcaption><p>Create and manage resources</p></figcaption></figure>

{% hint style="success" %}
How to use resources? You can create an SQL Runner adapter and choose the resource in the tab inspector.
{% endhint %}

<figure><img src="https://3121650445-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2swI1pjclnd3mBKYVhl%2Fuploads%2FzxSwbvUWFRA3Dlitk7Hl%2Fresource.png?alt=media&amp;token=ec272fff-3d3c-45d2-a9e8-0ce7045a98cc" alt=""><figcaption></figcaption></figure>


