forked from ballerina-platform/ballerina-distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the examples and fix the line break issue
- Loading branch information
Showing
24 changed files
with
95 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.