Databases in Plang

This article explores Plang, an intent-based programming language designed to interpret natural language. For more information, visit plang.is

Plang has a database built into the language. It uses an SQLite database. It’s simple to use.

Se…


This content originally appeared on DEV Community and was authored by Ingi

This article explores Plang, an intent-based programming language designed to interpret natural language. For more information, visit plang.is

Plang has a database built into the language. It uses an SQLite database. It's simple to use.

Setup Database

Define the table structure in the Setup.goal file.

Create Setup.goal in the root directory of your project. The project can be located anywhere on your computer.

Setup
- create table tasks, columns: 
    text(string, not null)
    due_date(datetime, default now)

Here we are defining the table tasks, with two columns: text and due_date.

If you are not familiar with Plang, there is not really any syntax; you just need to follow simple rules that structure the goal file.

So you can write the create table in multiple ways. You can write it the way you would like, as long as your intent is clear.

Now build the code and run the setup to create the table in the database.

plang exec Setup

plang exec both builds and runs the code.

Database Location

The database is located in .db/data.sqlite. This folder is hidden, so you might need to show hidden items in your operating system. You can open the database using any database tool that can read SQLite; I use DBeaver.

Insert, Update, and Select from Database

Let's insert and select some data from the database.

Create a new file Start.goal in your root folder:

Start
- insert into tasks, text='Buy milk', write into %id%
- insert into tasks, text='Fix car', due_date=%Now+2days%
- update tasks, set text='Buy milk now' where %id%
- select * from tasks, write to %tasks%
- delete from tasks
- write out %tasks%

You can now build this.

plang build

After the code has been built, you can run it:

plang

The default entry point of Plang apps is Start.goal, so you do not need to define the Start.goal when you execute plang in your terminal/console.

SQL Statements

You don't really need to write valid SQL statements. The Plang builder will convert your intent into a valid statement.

You can do something like this:

Start
- insert data into the tasks table, put the %text%, and have the due_date=%Now+1day%
- select the 10 newest rows from tasks, write to %tasks%
- write out %tasks%

Other Databases

Plang supports any other database as well. You can read more about it in the Services documentation.

More Information

If Plang is interesting to you, you should dig a bit deeper:


This content originally appeared on DEV Community and was authored by Ingi


Print Share Comment Cite Upload Translate Updates
APA

Ingi | Sciencx (2024-07-18T11:12:42+00:00) Databases in Plang. Retrieved from https://www.scien.cx/2024/07/18/databases-in-plang/

MLA
" » Databases in Plang." Ingi | Sciencx - Thursday July 18, 2024, https://www.scien.cx/2024/07/18/databases-in-plang/
HARVARD
Ingi | Sciencx Thursday July 18, 2024 » Databases in Plang., viewed ,<https://www.scien.cx/2024/07/18/databases-in-plang/>
VANCOUVER
Ingi | Sciencx - » Databases in Plang. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/18/databases-in-plang/
CHICAGO
" » Databases in Plang." Ingi | Sciencx - Accessed . https://www.scien.cx/2024/07/18/databases-in-plang/
IEEE
" » Databases in Plang." Ingi | Sciencx [Online]. Available: https://www.scien.cx/2024/07/18/databases-in-plang/. [Accessed: ]
rf:citation
» Databases in Plang | Ingi | Sciencx | https://www.scien.cx/2024/07/18/databases-in-plang/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.