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

Sql++ enhancements #16

Merged
merged 3 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions docs/Queries/query-result-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,37 @@ for (const result of resultSet) {

In this example, `hotelItems` is the alias used for the collection in the query, and it serves as the key in the `Result` objects within the `ResultSet`.

#### Example 2. Query Result Sets

```typescript
const query = database.createQuery('SELECT hotelItems.*, META().id as docId FROM inventory.hotel AS hotelItems WHERE city="Medway"');
const resultSet: ResultSet = await query.execute();

for (const result of resultSet) {
console.log(result['docId']);
console.log(result['hotelItems'].propertyName);
}
```

n this example, `hotelItems` is the alias used for the collection in the query, and it serves as the key in the `Result` objects within the `ResultSet`. Each `result` object also includes a `docId`, representing the document ID, allowing you to access both the document ID and the hotel item details.


#### Example 3. Query Result Sets

```typescript
const query = database.createQuery(`
SELECT *
FROM route
JOIN airline
ON route.airlineid = META(airline).id
WHERE airline.country = "France"
`);
const resultSet: ResultSet = await query.execute();

for (const result of resultSet) {
console.log(result['route'].propertyName); // Access properties from the route collection
console.log(result['airline'].propertyName); // Access properties from the airline collection
}
```

In this example, `route` and `airline` are the collections being queried and joined based on the `airlineid`. The `Result` objects within the `ResultSet` contain keys corresponding to these collection names, allowing you to access properties from both the `route` and `airline` collections. The query filters the results to only include airlines from France.
27 changes: 13 additions & 14 deletions docs/Queries/sqlplusplus.md
Original file line number Diff line number Diff line change
Expand Up @@ -1341,23 +1341,22 @@ for the features supported by SQL++ for Mobile but not by `QueryBuilder`.

You can provide runtime parameters to your SQL++ query to make it more flexible.
To specify substitutable parameters within your query string prefix the name
with `$` — see: [Example 51](#).
with `$` — see: [Example 51](#example-51-running-a-sql-query).

#### Example 51. Running a SQL++ Query

```dart
final db = await Database.openAsync('hotel');
final query = await Query.fromN1ql(
db,
r'''
SELECT META().id AS docId
FROM _
WHERE type = $type
''',
You can provide runtime parameters to your SQL++ query to make it more flexible. To specify substitutable parameters within your query string prefix the name with $ — see: [Example 51](#example-51-running-a-sql-query).

```typescript
const query = await database.createQuery(
'SELECT META().id AS docId FROM hotel WHERE country = $country'
);
query.parameters = Parameters({'type': 'hotel'});
final resultSet = query.execute();

const params = new Parameters();
params.setString('country','France')
query.parameters = params;
const resultSet = await query.execute();
```

1. Define a parameter placeholder `$type`.
2. Set the value of the `type` parameter.
1. Define a parameter placeholder `$country`.
2. Set the value of the `country` parameter.