Skip to content

Commit d5c04da

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

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

docs/site/Executing-database-commands.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,72 @@ 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+
66+
## Examples
67+
68+
### MySQL
69+
70+
Use parameterized queries to avoid SQL injection attacks.
71+
72+
```ts
73+
const result = await repository.execute('SELECT * FROM Products WHERE id = ?', [
74+
productId,
75+
]);
76+
```
77+
78+
### PostgreSQL
79+
80+
```ts
81+
const result = await repository.execute(
82+
'SELECT * FROM Products WHERE id = $1',
83+
[productId],
84+
);
85+
```
86+
87+
### MongoDB
88+
89+
```ts
90+
const result = await repository.execute('MyCollection', 'aggregate', [
91+
{$unwind: '$data'},
92+
{$out: 'tempData'},
93+
]);
94+
```
95+
96+
Use parameterized queries whenever possible instead of constructing SQL strings
97+
manually.
98+
3399
See API docs for parameter reference, additional information and examples:
34100

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

0 commit comments

Comments
 (0)