You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: ballerina/Module.md
+26-26
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This package provides relational database support for the `bal persist` feature, which provides functionality to store and query data from a relational database through a data model instead of writing SQL.
4
4
5
-
Currently, this package supports MySQL, MSSQL and PostgreSQL databases. However, we are also planning to add support for other relational databases such as Oracle.
5
+
Currently, this package supports MySQL, MSSQL, and PostgreSQL databases. However, we are also planning to add support for other relational databases such as Oracle.
6
6
7
7
## How to use with `bal persist`
8
8
@@ -61,20 +61,20 @@ The following table lists the Ballerina types supported by the MySQL data store
61
61
62
62
The following table lists the Ballerina types supported by the MSSQL data store and the corresponding SQL types used to store the data in the database.
63
63
64
-
| Ballerina type | SQL type |
65
-
|:----------------:|:---------------------:|
66
-
| int |INT |
67
-
| float |FLOAT |
68
-
| decimal | DECIMAL(38,30) |
69
-
| string | VARCHAR(191) |
70
-
| boolean |BIT |
71
-
| byte[]| VARBINARY(MAX) |
72
-
| () | NULL |
73
-
| time:Date| DATE |
74
-
| time:TimeOfDay| TIME |
75
-
| time:Utc|DATETIME2 |
76
-
| time:Civil|DATETIME2 |
77
-
| enum | VARCHAR with checks. |
64
+
| Ballerina type | SQL type |
65
+
|:----------------:|:--------------------:|
66
+
| int | INT |
67
+
| float | FLOAT |
68
+
| decimal | DECIMAL(38,30) |
69
+
| string | VARCHAR(191) |
70
+
| boolean | BIT |
71
+
| byte[]| VARBINARY(MAX) |
72
+
| () | NULL |
73
+
| time:Date| DATE |
74
+
| time:TimeOfDay| TIME |
75
+
| time:Utc| DATETIME2 |
76
+
| time:Civil| DATETIME2 |
77
+
| enum | VARCHAR with checks. |
78
78
79
79
### PostgreSQL
80
80
@@ -99,17 +99,17 @@ The default length for some SQL types can be changed using the [Advanced SQL typ
99
99
100
100
## Advanced SQL annotations
101
101
102
-
To have custom name and type mappings in the database implementation and to declare indexes, generated fields and custom foreign keys, the below annotations can be used in the data model definition. Note that these annotations can only be used with SQL data stores.
102
+
To have a custom name and type mappings in the database implementation and to declare indexes, generated fields, and custom foreign keys, the below annotations can be used in the data model definition. Note that these annotations can only be used with SQL data stores.
103
103
104
104
In order to use them, you must first import the `persist.sql` package to your data model definition file as follows.
105
105
106
106
```ballerina
107
107
import ballerinax/persist.sql;
108
108
```
109
109
110
-
### Mapping names with `Name` annotation
110
+
### Name mapping with `Name` annotation
111
111
112
-
- Map entity names to table names
112
+
- Map entity name to table name
113
113
114
114
```ballerina
115
115
@sql:Name {value: "people"}
@@ -122,7 +122,7 @@ type Person record {|
122
122
123
123
The `Person` entity will be mapped to the `people` table in the database.
124
124
125
-
- Map field names to column names
125
+
- Map field name to column name
126
126
127
127
```ballerina
128
128
type Person record {|
@@ -136,7 +136,7 @@ type Person record {|
136
136
137
137
The `id` field will be mapped to the `person_id` column in the database, and the `name` field will be mapped to the `full_name` column in the database.
138
138
139
-
### Mapping types
139
+
### Type mapping
140
140
141
141
#### `Varchar` annotation
142
142
@@ -177,7 +177,7 @@ type Person record {|
177
177
178
178
The `salary` field will have a `DECIMAL(10,2)` column in the database. The `@sql:Decimal` annotation can only be used on `decimal` fields.
179
179
180
-
### Declaring indexes
180
+
### Declare indexes
181
181
182
182
#### `Index` annotation
183
183
@@ -214,7 +214,7 @@ type Person record {|
214
214
215
215
The unique index `idx_person` is a composite unique index consisting of `nic` and `name` fields. `idx_another` is just another unique index on the `name` field. The `address` field also has the `@sql:UniqueIndex` annotation without the `name` property. Here, the index name will be generated by `persist` in the `unique_idx_[FIELD_NAME]` format, in which case the index name for the `address` field becomes `unique_idx_address`.
216
216
217
-
### Declaring generated fields with `Generated` annotation
217
+
### Declare generated fields with `Generated` annotation
218
218
219
219
The `@sql:Generated` annotation is used to declare a field as a generated field. This annotation can only be used on `readonly int` fields. Currently, only the `AUTO_INCREMENT` or an equivalent generation strategy is supported.
220
220
@@ -235,9 +235,9 @@ The `id` field will be auto-generated and the [`PersonInsert`](/learn/persist-cl
235
235
|`MSSQL`|`IDENTITY(1,1)`|
236
236
|`PostgreSQL`|`SERIAL`|
237
237
238
-
### Declaring custom foreign keys with `Relation` annotation
238
+
### Declare custom foreign keys with `Relation` annotation
239
239
240
-
The `@sql:Relation` annotation can be used to declare your own custom foreign key field name. You must put the foreign key on the correct side of the relationship (ownerside) and the key field must exist on the record type, and must be of the same type as the primary key of the referred entity. This is particularly useful when a foreign key is also a part of the composite primary key.
240
+
The `@sql:Relation` annotation can be used to declare your own custom foreign key field. You must put the foreign key on the correct side of the relationship (owner) and the key field must exist on the record type, and must be of the same type as the primary key of the referred entity. This is particularly useful when a foreign key is also a part of the composite primary key.
241
241
242
242
```ballerina
243
243
type Car record {|
@@ -255,7 +255,7 @@ type User record {|
255
255
|};
256
256
```
257
257
258
-
The `keys` field accepts an array of foreign keys and the length of it must be same as the number of primary keys the referring entity has. Here, the field `userId` is used as the foreign key for the relation `owner` and it has been declared so through the `@sql:Relation` annotation. When the `@sql:Relation` annotation is used in a relation field, the foreign key will not be generated by default.
258
+
The `keys` field accepts an array of foreign keys and the length of it must be the same as the number of primary keys the referring entity has. Here, the field `userId` is used as the foreign key for the relation `owner` and it has been declared so through the `@sql:Relation` annotation. When the `@sql:Relation` annotation is used in a relation field, the foreign key will not be generated by default.
259
259
260
260
## Configuration
261
261
You need to set values for the following basic configuration parameters in the `Config.toml` file in your project to use the MySQL data store.
@@ -268,7 +268,7 @@ You need to set values for the following basic configuration parameters in the `
268
268
| password | The password of the DB server. |
269
269
| database | The name of the database to be used. |
270
270
271
-
The following is a sample `Config.toml` file with the MySQL data store configuration. This will be generated by the `bal build` or `bal persist generate` command (depending on how you have configured the application).
271
+
The following is a sample `Config.toml` file with the MySQL data store configuration. This will be generated by the `bal build` or `bal persist generate` command (depending on how you generate the client API).
Copy file name to clipboardexpand all lines: ballerina/Package.md
+29-29
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This package provides relational database support for the `bal persist` feature, which provides functionality to store and query data from a relational database through a data model instead of writing SQL.
4
4
5
-
Currently, this package supports MySQL, MSSQL and PostgreSQL databases. However, we are also planning to add support for other relational databases such as Oracle.
5
+
Currently, this package supports MySQL, MSSQL, and PostgreSQL databases. However, we are also planning to add support for other relational databases such as Oracle.
6
6
7
7
## How to use with `bal persist`
8
8
@@ -15,7 +15,7 @@ By default, `bal persist` utilizes the in-memory data store. Therefore, you must
15
15
```
16
16
$ bal persist add --datastore [mysql/mssql/postgresql] --module <module_name>
17
17
```
18
-
18
+
19
19
2. After defining the entities, build the application using the following command,
20
20
21
21
```
@@ -29,13 +29,13 @@ By default, `bal persist` utilizes the in-memory data store. Therefore, you must
29
29
```
30
30
$ bal persist init
31
31
```
32
-
32
+
33
33
2. Generate the persist client using the following command,
34
34
35
35
```
36
36
$ bal persist generate --datastore [mysql/mssql/postgresql] --module <module_name>
37
37
```
38
-
38
+
39
39
## Supported Ballerina Types
40
40
41
41
### MySQL
@@ -61,20 +61,20 @@ The following table lists the Ballerina types supported by the MySQL data store
61
61
62
62
The following table lists the Ballerina types supported by the MSSQL data store and the corresponding SQL types used to store the data in the database.
63
63
64
-
| Ballerina type | SQL type |
65
-
|:----------------:|:---------------------:|
66
-
| int |INT |
67
-
| float |FLOAT |
68
-
| decimal | DECIMAL(38,30) |
69
-
| string | VARCHAR(191) |
70
-
| boolean |BIT |
71
-
| byte[]| VARBINARY(MAX) |
72
-
| () | NULL |
73
-
| time:Date| DATE |
74
-
| time:TimeOfDay| TIME |
75
-
| time:Utc|DATETIME2 |
76
-
| time:Civil|DATETIME2 |
77
-
| enum | VARCHAR with checks. |
64
+
| Ballerina type | SQL type |
65
+
|:----------------:|:--------------------:|
66
+
| int | INT |
67
+
| float | FLOAT |
68
+
| decimal | DECIMAL(38,30) |
69
+
| string | VARCHAR(191) |
70
+
| boolean | BIT |
71
+
| byte[]| VARBINARY(MAX) |
72
+
| () | NULL |
73
+
| time:Date| DATE |
74
+
| time:TimeOfDay| TIME |
75
+
| time:Utc| DATETIME2 |
76
+
| time:Civil| DATETIME2 |
77
+
| enum | VARCHAR with checks. |
78
78
79
79
### PostgreSQL
80
80
@@ -99,17 +99,17 @@ The default length for some SQL types can be changed using the [Advanced SQL typ
99
99
100
100
## Advanced SQL annotations
101
101
102
-
To have custom name and type mappings in the database implementation and to declare indexes, generated fields and custom foreign keys, the below annotations can be used in the data model definition. Note that these annotations can only be used with SQL data stores.
102
+
To have a custom name and type mappings in the database implementation and to declare indexes, generated fields, and custom foreign keys, the below annotations can be used in the data model definition. Note that these annotations can only be used with SQL data stores.
103
103
104
104
In order to use them, you must first import the `persist.sql` package to your data model definition file as follows.
105
105
106
106
```ballerina
107
107
import ballerinax/persist.sql;
108
108
```
109
109
110
-
### Mapping names with `Name` annotation
110
+
### Name mapping with `Name` annotation
111
111
112
-
- Map entity names to table names
112
+
- Map entity name to table name
113
113
114
114
```ballerina
115
115
@sql:Name {value: "people"}
@@ -122,7 +122,7 @@ type Person record {|
122
122
123
123
The `Person` entity will be mapped to the `people` table in the database.
124
124
125
-
- Map field names to column names
125
+
- Map field name to column name
126
126
127
127
```ballerina
128
128
type Person record {|
@@ -136,7 +136,7 @@ type Person record {|
136
136
137
137
The `id` field will be mapped to the `person_id` column in the database, and the `name` field will be mapped to the `full_name` column in the database.
138
138
139
-
### Mapping types
139
+
### Type mapping
140
140
141
141
#### `Varchar` annotation
142
142
@@ -177,7 +177,7 @@ type Person record {|
177
177
178
178
The `salary` field will have a `DECIMAL(10,2)` column in the database. The `@sql:Decimal` annotation can only be used on `decimal` fields.
179
179
180
-
### Declaring indexes
180
+
### Declare indexes
181
181
182
182
#### `Index` annotation
183
183
@@ -214,7 +214,7 @@ type Person record {|
214
214
215
215
The unique index `idx_person` is a composite unique index consisting of `nic` and `name` fields. `idx_another` is just another unique index on the `name` field. The `address` field also has the `@sql:UniqueIndex` annotation without the `name` property. Here, the index name will be generated by `persist` in the `unique_idx_[FIELD_NAME]` format, in which case the index name for the `address` field becomes `unique_idx_address`.
216
216
217
-
### Declaring generated fields with `Generated` annotation
217
+
### Declare generated fields with `Generated` annotation
218
218
219
219
The `@sql:Generated` annotation is used to declare a field as a generated field. This annotation can only be used on `readonly int` fields. Currently, only the `AUTO_INCREMENT` or an equivalent generation strategy is supported.
220
220
@@ -235,9 +235,9 @@ The `id` field will be auto-generated and the [`PersonInsert`](/learn/persist-cl
235
235
|`MSSQL`|`IDENTITY(1,1)`|
236
236
|`PostgreSQL`|`SERIAL`|
237
237
238
-
### Declaring custom foreign keys with `Relation` annotation
238
+
### Declare custom foreign keys with `Relation` annotation
239
239
240
-
The `@sql:Relation` annotation can be used to declare your own custom foreign key field name. You must put the foreign key on the correct side of the relationship (ownerside) and the key field must exist on the record type, and must be of the same type as the primary key of the referred entity. This is particularly useful when a foreign key is also a part of the composite primary key.
240
+
The `@sql:Relation` annotation can be used to declare your own custom foreign key field. You must put the foreign key on the correct side of the relationship (owner) and the key field must exist on the record type, and must be of the same type as the primary key of the referred entity. This is particularly useful when a foreign key is also a part of the composite primary key.
241
241
242
242
```ballerina
243
243
type Car record {|
@@ -255,7 +255,7 @@ type User record {|
255
255
|};
256
256
```
257
257
258
-
The `keys` field accepts an array of foreign keys and the length of it must be same as the number of primary keys the referring entity has. Here, the field `userId` is used as the foreign key for the relation `owner` and it has been declared so through the `@sql:Relation` annotation. When the `@sql:Relation` annotation is used in a relation field, the foreign key will not be generated by default.
258
+
The `keys` field accepts an array of foreign keys and the length of it must be the same as the number of primary keys the referring entity has. Here, the field `userId` is used as the foreign key for the relation `owner` and it has been declared so through the `@sql:Relation` annotation. When the `@sql:Relation` annotation is used in a relation field, the foreign key will not be generated by default.
259
259
260
260
## Configuration
261
261
You need to set values for the following basic configuration parameters in the `Config.toml` file in your project to use the MySQL data store.
@@ -268,7 +268,7 @@ You need to set values for the following basic configuration parameters in the `
268
268
| password | The password of the DB server. |
269
269
| database | The name of the database to be used. |
270
270
271
-
The following is a sample `Config.toml` file with the MySQL data store configuration. This will be generated by the `bal build` or `bal persist generate` command (depending on how you have configured the application).
271
+
The following is a sample `Config.toml` file with the MySQL data store configuration. This will be generated by the `bal build` or `bal persist generate` command (depending on how you generate the client API).
0 commit comments