File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ function sidebarDocs(): DefaultTheme.SidebarItem[] {
123123 collapsed : false ,
124124 items : [
125125 { text : "Query Methods" , link : "query-methods" } ,
126+ { text : "Raw SQL" , link : "raw-sql" } ,
126127 { text : "Transaction" , link : "transaction" } ,
127128 { text : "Association" , link : "association" } ,
128129 { text : "Data Types" , link : "data-types" } ,
Original file line number Diff line number Diff line change 1+ # Raw SQL
2+
3+ Queryx provides direct support for executing raw SQL queries through the following methods.
4+
5+ ## Query
6+
7+ ` Query ` returns all rows from the database.
8+
9+ ::: tabs key: lang
10+ == Go
11+
12+ ``` go
13+ type User struct {
14+ Name string ` db:"user_name"`
15+ }
16+ var users []User
17+ err := c.Query (" select name as user_name from users where id in (?)" , []int64 {1 , 2 }).Scan (&users)
18+ ```
19+
20+ == TypeScript
21+
22+ ``` typescript
23+ let users = await c .query <{ user_name: string }>(
24+ " select name as user_name from users where id in (?)" ,
25+ [1 , 2 ],
26+ );
27+ ```
28+
29+ :::
30+
31+ ## Query One
32+
33+ ` QueryOne ` returns at most a single row from the database.
34+
35+ ::: tabs key: lang
36+ == Go
37+
38+ ``` go
39+ var user struct {
40+ ID int64 ` db:"user_id"`
41+ }
42+ err = c.QueryOne (" select id as user_id from users where id = ?" , 1 ).Scan (&user)
43+ ```
44+
45+ == TypeScript
46+
47+ ``` typescript
48+ let user = await c .queryOne <{ user_id: number }>(
49+ " select id as user_id from users where id = ?" ,
50+ 1 ,
51+ );
52+ ```
53+
54+ :::
55+
56+ ## Exec
57+
58+ ` Exec ` for SQL statement that don't return data.
59+
60+ ::: tabs key: lang
61+ == Go
62+
63+ ``` go
64+ rowsAffected , err := c.Exec (" update users set name = ? where id = ?" , " test1" , 1 )
65+ ```
66+
67+ == TypeScript
68+
69+ ``` typescript
70+ let rowAffected = await c .exec (
71+ " update users set name = ? where id = ?" ,
72+ " test1" ,
73+ 1 ,
74+ );
75+ ```
76+
77+ :::
You can’t perform that action at this time.
0 commit comments