Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persists code samples for ballerina bff #3

Merged
merged 13 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md

This file was deleted.

46 changes: 46 additions & 0 deletions persistently-store-data-using-Ballerina/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Persistently store data using Ballerina

The [bal persist](https://central.ballerina.io/ballerina/persist/latest) feature offer a straightforward way to work with data sources, making it easier to build an application's data access layer. By simply defining the required Ballerina records, the `persist` package auto-generates all data access functions. This eliminates repetitive code, providing a simplified interface for inserting, updating, and querying data with data tables directly mapped into Ballerina records.

## Set up

1. Clone the project

```
$ git clone https://github.com/ballerina-guides/bff-samples.git
```

2. Add a new file named `Config.toml` in the `/backend_server` directory and add the following configurations for the MySQL server.

```
[data_persistence]
host = "<Database Host>"
port = <Database Port>
user = <Username of MySQL user>
password = <Password of MySQL user>
database = <database name>
```

3. Run the following SQL query to create a new database in the MySQL server.

```
CREATE DATABASE <database name>;
```

4. Run the SQL scripts `/backend_server/generated/script.sql` and `/backend_server/resources/init-data.sql` to create the tables and insert data into the tables in the MySQL database.

5. Open a new Terminal in the project path and run the Ballerina service

```
$ cd bff-samples
$ cd persistently-store-data-using-Ballerina/backend_server
$ bal run
```

6. Then open a new terminal in the project path and run the React service

```
$ cd bff-samples
$ cd persistently-store-data-using-Ballerina/frontend_server
$ npm run dev
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"image": "ballerina/ballerina-devcontainer:2201.6.0",
"extensions": ["WSO2.ballerina"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
org = "bff_samples"
name = "data_persistence"
version = "0.1.0"
distribution = "2201.8.2"

[build-options]
observabilityIncluded = true

[persist]
datastore = "mysql"
module = "data_persistence"

[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "persist.sql-native"
version = "1.2.0"
Loading