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 4 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
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# bff-samples
## Ballerina Persists module with databases
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved

Ballerina's persistence features 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 persistence 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 to Ballerina records.
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved

SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
1. Clone the project

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

2. Install MySQL on the machine
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved

3. Add a new file `Config.toml` in the `/backend_server` directory and add the following configurations
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

5. 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.

6. Open a new Terminal in the project path and run the Ballerina Server
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved

```
$ cd bff-samples
$ cd persists/backend_server
$ bal run
```

4. Then open a new terminal in the project path and run the React server

```
$ cd bff-samples
$ cd persists/frontend_server
$ npm run dev
```
4 changes: 4 additions & 0 deletions persists/backend_server/.devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"image": "ballerina/ballerina-devcontainer:2201.6.0",
"extensions": ["WSO2.ballerina"],
}
2 changes: 2 additions & 0 deletions persists/backend_server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Config.toml
17 changes: 17 additions & 0 deletions persists/backend_server/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
org = "bff_samples"
name = "persists"
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
version = "0.1.0"
distribution = "2201.8.2"

[build-options]
observabilityIncluded = true

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

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