Skip to content

Commit

Permalink
Update the examples and fix the line break issue
Browse files Browse the repository at this point in the history
  • Loading branch information
daneshk committed Aug 25, 2024
1 parent adf7b23 commit f173c26
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 118 deletions.
10 changes: 4 additions & 6 deletions examples/persist-create/persist_create.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# Persist write - Create record/records

The bal persist feature provides support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once the model is defined, the client API is generated with resources based on the model. The generated
API can be used to query and manipulate the persistent data in the application.
The bal persist feature provides support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once the model is defined, the client API is generated with resources based on the model. The generated API can be used to query and manipulate the persistent data in the application.
The generated client API provides a `post` resource method to persist record/records to the data store.

> **Note:** This example uses the Ballerina tables as the data store. You can use MySQL and Google Sheets as the data store as well. For more information, see [Supported Data Stores](/learn/supported-data-stores/).
> **Note:** This example uses the Ballerina tables as the data store. For more information about other supported data stores, see [Supported Data Stores](/learn/supported-data-stores/).
#### Initialize the project
Execute the command below to initialize `bal persist` in the project.

::: out persist_init.out :::

#### Model the data

Add the `Employee` entity with the following fields in the `model.bal` file inside the `persist` directory.

::: code persist_model.bal :::

#### Generate client APIs
> **Note:** The client APIs can be generated using the `bal persist generate` command which is one time generation and the generated client code is a part of the project. We can also integrate the client code generation with the build process of the project by executing the `bal persist add` command. This will add the client code generation as a build task in the `Ballerina.toml` file. For more information, see [Persist CLI Commands](learn/persist-cli-tool/).
Execute the command below to generate the Ballerina client API.

::: out persist_generate.out :::

#### Use the generated client API

Using the generated client API, you can persist record/records to the data store with the `post` resource method.

::: code persist_create.bal :::

#### Run the program

Execute the command below to run the program.

::: out persist_create.out :::
5 changes: 2 additions & 3 deletions examples/persist-create/persist_generate.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$ bal persist generate
$ bal persist generate --datastore inmemory --module store

Generated Ballerina Client, Types, and Scripts to ./generated/store directory.
You can now start using Ballerina Client in your code.
Persist client and entity types generated successfully in the store directory.
12 changes: 6 additions & 6 deletions examples/persist-create/persist_init.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ bal persist init --module store
$ bal persist init

Initialized persistence in your Ballerina project.

Your Persist schema is at persist/model.bal.
You can now update it with entity definitions.
Initialized the package for persistence.

Next steps:
Run bal persist generate to generate the Ballerina Client, Types, and Scripts. You can then start querying your database.
1. Define your data model in "persist/model.bal".
2. Execute `bal persist add --datastore <datastore> --module <module>` to add an entry to "Ballerina.toml" for integrating code generation with the package build process.
OR
Execute `bal persist generate --datastore <datastore> --module <module>` for a one-time generation of the client.
10 changes: 4 additions & 6 deletions examples/persist-delete/persist_delete.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# Persist write - Delete record

The bal persist feature provides support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once the model is defined, the client API is generated with resources based on the model. The generated
API can be used to query and manipulate the persistent data in the application.
The bal persist feature provides support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once the model is defined, the client API is generated with resources based on the model. The generated API can be used to query and manipulate the persistent data in the application.
The generated client API provides a `delete` resource method to delete records from the data store.

> **Note:** This example uses Ballerina tables as the data store. You can use MySQL and Google Sheets as the data store as well. For more information, see [Supported Data Stores](/learn/supported-data-stores/).
> **Note:** This example uses the Ballerina tables as the data store. For more information about other supported data stores, see [Supported Data Stores](/learn/supported-data-stores/).
#### Initialize the project
Execute the command below to initialize `bal persist` in the project.

::: out persist_init.out :::

#### Model the data

Add `Employee` entity with the following fields in the `model.bal` file inside the `persist` directory.

::: code persist_model.bal :::

#### Generate client APIs
> **Note:** The client APIs can be generated using the `bal persist generate` command which is one time generation and the generated client code is a part of the project. We can also integrate the client code generation with the build process of the project by executing the `bal persist add` command. This will add the client code generation as a build task in the `Ballerina.toml` file. For more information, see [Persist CLI Commands](learn/persist-cli-tool/).
Execute the command below to generate the Ballerina client API.

::: out persist_generate.out :::

#### Use the generated client API

Using the generated client API, you can delete records from the data store with the `delete` resource method.

::: code persist_delete.bal :::

#### Run the program

Execute the command below to run the program.

::: out persist_delete.out :::
5 changes: 2 additions & 3 deletions examples/persist-delete/persist_generate.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$ bal persist generate
$ bal persist generate --datastore inmemory --module store

Generated Ballerina Client, Types, and Scripts to ./generated/store directory.
You can now start using Ballerina Client in your code.
Persist client and entity types generated successfully in the store directory.
12 changes: 6 additions & 6 deletions examples/persist-delete/persist_init.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ bal persist init --module store
$ bal persist init

Initialized persistence in your Ballerina project.

Your Persist schema is at persist/model.bal.
You can now update it with entity definitions.
Initialized the package for persistence.

Next steps:
Run bal persist generate to generate the Ballerina Client, Types, and Scripts. You can then start querying your database.
1. Define your data model in "persist/model.bal".
2. Execute `bal persist add --datastore <datastore> --module <module>` to add an entry to "Ballerina.toml" for integrating code generation with the package build process.
OR
Execute `bal persist generate --datastore <datastore> --module <module>` for a one-time generation of the client.
10 changes: 4 additions & 6 deletions examples/persist-filtering/persist_filtering.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# Persist read - Filter and sort

The bal persist feature provide support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once model is defined, the client API is generated with resources based on the model. The generated
API can be used to query and manipulate the persistent data in the application.
The bal persist feature provide support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once model is defined, the client API is generated with resources based on the model. The generated API can be used to query and manipulate the persistent data in the application.
The generated client API provides `get` resource method to retrieve all records from the data store. As the `get` resource method returns a stream of records, we can use query expressions to do additional filter. For more information, see [Query Expressions](/learn/by-example/query-expressions/).

> **Note:** This example uses Ballerina tables as the data store. You can use MySQL and Google Sheets as the data store as well. For more information, see [Supported Data Stores](/learn/supported-data-stores/).
> **Note:** This example uses the Ballerina tables as the data store. For more information about other supported data stores, see [Supported Data Stores](/learn/supported-data-stores/).
#### Initialize the project
Execute the command below to initialize `bal persist` in the project.

::: out persist_init.out :::

#### Model the data

Add `Employee` entity with the following fields in the `model.bal` file inside the `persist` directory.

::: code persist_model.bal :::

#### Generate client APIs
> **Note:** The client APIs can be generated using the `bal persist generate` command which is one time generation and the generated client code is a part of the project. We can also integrate the client code generation with the build process of the project by executing the `bal persist add` command. This will add the client code generation as a build task in the `Ballerina.toml` file. For more information, see [Persist CLI Commands](learn/persist-cli-tool/).
Execute the command below to generate the Ballerina client API.

::: out persist_generate.out :::

#### Use the generated client API

Using the generated client API, we can retrieve all records from the data store. The `get` resource method returns a stream of records. We can iterate through the stream and print the records.

::: code persist_filtering.bal :::

#### Run the program

Execute the command below to run the program.

::: out persist_filtering.out :::
5 changes: 2 additions & 3 deletions examples/persist-filtering/persist_generate.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$ bal persist generate
$ bal persist generate --datastore inmemory --module store

Generated Ballerina Client, Types, and Scripts to ./generated/store directory.
You can now start using Ballerina Client in your code.
Persist client and entity types generated successfully in the store directory.
12 changes: 6 additions & 6 deletions examples/persist-filtering/persist_init.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ bal persist init --module store
$ bal persist init

Initialized persistence in your Ballerina project.

Your Persist schema is at persist/model.bal.
You can now update it with entity definitions.
Initialized the package for persistence.

Next steps:
Run bal persist generate to generate the Ballerina Client, Types, and Scripts. You can then start querying your database.
1. Define your data model in "persist/model.bal".
2. Execute `bal persist add --datastore <datastore> --module <module>` to add an entry to "Ballerina.toml" for integrating code generation with the package build process.
OR
Execute `bal persist generate --datastore <datastore> --module <module>` for a one-time generation of the client.
5 changes: 2 additions & 3 deletions examples/persist-get-all/persist_generate.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$ bal persist generate
$ bal persist generate --datastore inmemory --module store

Generated Ballerina Client, Types, and Scripts to ./generated/store directory.
You can now start using Ballerina Client in your code.
Persist client and entity types generated successfully in the store directory.
7 changes: 3 additions & 4 deletions examples/persist-get-all/persist_get_all.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@ The bal persist feature provides support to manage data persistence in a Balleri

The generated client API provides a `get` resource method to retrieve all records from the data store.

> **Note:** This example uses Ballerina tables as the data store. You can use MySQL and Google Sheets as the data store as well. For more information, see [Supported Data Stores](/learn/supported-data-stores/).
> **Note:** This example uses the Ballerina tables as the data store. For more information about other supported data stores, see [Supported Data Stores](/learn/supported-data-stores/).
#### Initialize the project
Execute the command below to initialize `bal persist` in the project.

::: out persist_init.out :::

#### Model the data

Add `Employee` entity with the following fields in the `model.bal` file inside the `persist` directory.

::: code persist_model.bal :::

#### Generate client APIs
> **Note:** The client APIs can be generated using the `bal persist generate` command which is one time generation and the generated client code is a part of the project. We can also integrate the client code generation with the build process of the project by executing the `bal persist add` command. This will add the client code generation as a build task in the `Ballerina.toml` file. For more information, see [Persist CLI Commands](learn/persist-cli-tool/).
Execute the command below to generate the Ballerina client API.

::: out persist_generate.out :::

#### Use the generated client API

Using the generated client API, we can retrieve all records from the data store. The `get` resource method returns a stream of records. We can iterate through the stream and print the records.

::: code persist_get_all.bal :::

#### Run the program

Execute the command below to run the program.

::: out persist_get_all.out :::
12 changes: 6 additions & 6 deletions examples/persist-get-all/persist_init.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ bal persist init --module store
$ bal persist init

Initialized persistence in your Ballerina project.

Your Persist schema is at persist/model.bal.
You can now update it with entity definitions.
Initialized the package for persistence.

Next steps:
Run bal persist generate to generate the Ballerina Client, Types, and Scripts. You can then start querying your database.
1. Define your data model in "persist/model.bal".
2. Execute `bal persist add --datastore <datastore> --module <module>` to add an entry to "Ballerina.toml" for integrating code generation with the package build process.
OR
Execute `bal persist generate --datastore <datastore> --module <module>` for a one-time generation of the client.
5 changes: 2 additions & 3 deletions examples/persist-get-by-key/persist_generate.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$ bal persist generate
$ bal persist generate --datastore inmemory --module store

Generated Ballerina Client, Types, and Scripts to ./generated/store directory.
You can now start using Ballerina Client in your code.
Persist client and entity types generated successfully in the store directory.
10 changes: 4 additions & 6 deletions examples/persist-get-by-key/persist_get_by_key.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
# Persist read - Get record by key

The bal persist feature provides support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once the model is defined, the client API is generated with resources based on the model. The generated
API can be used to query and manipulate the persistent data in the application.
The bal persist feature provides support to manage data persistence in a Ballerina package. It starts with defining the application's data model. Once the model is defined, the client API is generated with resources based on the model. The generated API can be used to query and manipulate the persistent data in the application.
The generated client API provides `get by key` resource method to retrieve the record by the key from the data store.

> **Note:** This example uses Ballerina tables as the data store. You can use MySQL and Google Sheets as the data store as well. For more information, see [Supported Data Stores](/learn/supported-data-stores/).
> **Note:** This example uses the Ballerina tables as the data store. For more information about other supported data stores, see [Supported Data Stores](/learn/supported-data-stores/).
#### Initialize the project
Execute the command below to initialize `bal persist` in the project.

::: out persist_init.out :::

#### Model the data

Add `Employee` entity with the following fields in the `model.bal` file inside the `persist` directory.

::: code persist_model.bal :::

#### Generate client APIs
> **Note:** The client APIs can be generated using the `bal persist generate` command which is one time generation and the generated client code is a part of the project. We can also integrate the client code generation with the build process of the project by executing the `bal persist add` command. This will add the client code generation as a build task in the `Ballerina.toml` file. For more information, see [Persist CLI Commands](learn/persist-cli-tool/).
Execute the command below to generate the Ballerina client API.

::: out persist_generate.out :::

#### Use the generated client API

Using the generated client API, you can retrieve the record by key from the data store. The `get by key` resource method returns a record or error if no records are found for the given key.

::: code persist_get_by_key.bal :::

#### Run the program

Execute the command below to run the program.

::: out persist_get_by_key.out :::
12 changes: 6 additions & 6 deletions examples/persist-get-by-key/persist_init.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ bal persist init --module store
$ bal persist init

Initialized persistence in your Ballerina project.

Your Persist schema is at persist/model.bal.
You can now update it with entity definitions.
Initialized the package for persistence.

Next steps:
Run bal persist generate to generate the Ballerina Client, Types, and Scripts. You can then start querying your database.
1. Define your data model in "persist/model.bal".
2. Execute `bal persist add --datastore <datastore> --module <module>` to add an entry to "Ballerina.toml" for integrating code generation with the package build process.
OR
Execute `bal persist generate --datastore <datastore> --module <module>` for a one-time generation of the client.
5 changes: 2 additions & 3 deletions examples/persist-relation-queries/persist_generate.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$ bal persist generate
$ bal persist generate --datastore inmemory --module store

Generated Ballerina Client, Types, and Scripts to ./generated/store directory.
You can now start using Ballerina Client in your code.
Persist client and entity types generated successfully in the store directory.
12 changes: 6 additions & 6 deletions examples/persist-relation-queries/persist_init.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$ bal persist init --module store
$ bal persist init

Initialized persistence in your Ballerina project.

Your Persist schema is at persist/model.bal.
You can now update it with entity definitions.
Initialized the package for persistence.

Next steps:
Run bal persist generate to generate the Ballerina Client, Types, and Scripts. You can then start querying your database.
1. Define your data model in "persist/model.bal".
2. Execute `bal persist add --datastore <datastore> --module <module>` to add an entry to "Ballerina.toml" for integrating code generation with the package build process.
OR
Execute `bal persist generate --datastore <datastore> --module <module>` for a one-time generation of the client.
Loading

0 comments on commit f173c26

Please sign in to comment.