Skip to content

Commit 05d5367

Browse files
committed
docs: add Repository.execute examples
1 parent 945a392 commit 05d5367

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

docs/site/Executing-database-commands.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,42 @@ Example use:
2929
```ts
3030
const result = await repository.execute('SELECT * FROM Products');
3131
```
32+
## Examples
33+
34+
### MySQL
35+
36+
Use parameterized queries to avoid SQL injection attacks.
37+
38+
```ts
39+
const result = await repository.execute(
40+
'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(
58+
'MyCollection',
59+
'aggregate',
60+
[
61+
{$unwind: '$data'},
62+
{$out: 'tempData'},
63+
]
64+
);
65+
```
66+
67+
Use parameterized queries whenever possible instead of constructing SQL strings manually.
3268

3369
See API docs for parameter reference, additional information and examples:
3470

0 commit comments

Comments
 (0)