Skip to content

Commit de47d6c

Browse files
committed
docs: add Repository.execute examples
Signed-off-by: vivekpatil017 <vivekpatil9902@gmail.com>
1 parent 945a392 commit de47d6c

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

docs/site/Executing-database-commands.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,39 @@ Example use:
3030
const result = await repository.execute('SELECT * FROM Products');
3131
```
3232

33+
## Examples
34+
35+
### MySQL
36+
37+
Use parameterized queries to avoid SQL injection attacks.
38+
39+
```ts
40+
const result = await repository.execute('SELECT * FROM Products WHERE id = ?', [
41+
productId,
42+
]);
43+
```
44+
45+
### PostgreSQL
46+
47+
```ts
48+
const result = await repository.execute(
49+
'SELECT * FROM Products WHERE id = $1',
50+
[productId],
51+
);
52+
```
53+
54+
### MongoDB
55+
56+
```ts
57+
const result = await repository.execute('MyCollection', 'aggregate', [
58+
{$unwind: '$data'},
59+
{$out: 'tempData'},
60+
]);
61+
```
62+
63+
Use parameterized queries whenever possible instead of constructing SQL strings
64+
manually.
65+
3366
See API docs for parameter reference, additional information and examples:
3467

3568
- [SQL variant](./apidocs/repository.defaultcrudrepository.execute.md)

0 commit comments

Comments
 (0)