Tutorial #3. Account manager.

This tutorial describes how to store query and update your accounts from database.

By default scripts don't have database attached. You have to tell BAS, that this script will use database and what structure it will have. Start doing it by pressing "Show Database" button. 

"Show Database" button will open database panel, which controls all necessary tools to manipulate database. On the top you see database state, which is offline right now. Lets fix it and create database, hit "Create database" button.

First of all you need to define database structure, which tables and columns will it have. It is easy to do with "Schema editor". Lets create one table "accounts" with two columns "login" and "password"

Database structure changes requires BAS restart. So save changes and agree to restart application.

After restart you can visit database panel and see, that database is available now. And here you have 2 new options: delete database and data manager. Click on data manager, this will bring tool, which can find and change every record available in your new database.

Data manager contains 2 pannels: groups and records. Groups can be used to put your data in order. For example, to place trusted accounts in one group and just created in another.

There is no records in your database, you can import them from the text file. Click on Convert -> Import Csv. Import window lets you choose csv format.

After import operation success, you will have a new group and records in it. This data is persistent. BAS will store it between restarts.

You did a lot by now, created database and added records to it, but how to use them? The easiest way is to use resources. Create resoure with type database.

And thats it, now you can work with database as with regular files, in fact you can allow your users to choose, which data source they want to use.

Resource from database returns string with all columns in csv format, last piece of csv line is database id. It easy to parse it with "Parse Line" action.

Recources is not only way to interact with database, there is also Database module, which contains api to create update and delete records in any part of the script.

Consider following example, you want to check every account, if it is suspended and save that information in database. We will make a new column inside database "valid", iterate over every record and set valid column to true or false. But lets start from creating new column, open schema editor and hit "add column" button.

Login and password fileds had string type, but for "valid" column we need boolean type.

After you update schema and restart BAS new column will be added, all prevoius data is saved.

Now lets actually check every account. We don't write a real code which uses http client or browser, but just set valid column depending on random value. Script structure is on top image.

Use "Update Record" action to update last record, from resource.

Here is new script version with database updates.

After all data is processed, records will look like this. 

You see, that some records are valid, some are not. Lets create another group "valid accounts" and put all good accs there. Data manager has filter functionality, use it to filter bad accounts.

Valid accounts group can be used now as resource inputs. Note, that data manager is available to every script user, not only to developers. So users may create groups independently.

Right now you have created account checker, but what if you want interact with another script. Lets say you account creator and you want these two scripts to share same database. Thats when database global id comes in hand. Set both script same database id and same schema and they will work together.

Database id is located inside database panel. Database id is generated on first script run, but you can change it later. Create new account creator script and set copy database id from account checker.

You also need to copy schema. You may create all columns and tables again, but there is easier way. Just go to the text mode and copy schema as text.

After restart both project will share same database!

The last step of this tutorial is to finish account creator and add records to database. Action insert record can help you with this.

Fill every column with corresponding fields.

And here is new record!