Skip to content
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
1 change: 1 addition & 0 deletions website/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function sidebarDocs(): DefaultTheme.SidebarItem[] {
collapsed: false,
items: [
{ text: "Query Methods", link: "query-methods" },
{ text: "Raw SQL", link: "raw-sql" },
{ text: "Transaction", link: "transaction" },
{ text: "Association", link: "association" },
{ text: "Data Types", link: "data-types" },
Expand Down
77 changes: 77 additions & 0 deletions website/docs/raw-sql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Raw SQL

Queryx provides direct support for executing raw SQL queries through the following methods.

## Query

`Query` returns all rows from the database.

::: tabs key:lang
== Go

```go
type User struct {
Name string `db:"user_name"`
}
var users []User
err := c.Query("select name as user_name from users where id in (?)", []int64{1, 2}).Scan(&users)
```

== TypeScript

```typescript
let users = await c.query<{ user_name: string }>(
"select name as user_name from users where id in (?)",
[1, 2],
);
```

:::

## Query One

`QueryOne` returns at most a single row from the database.

::: tabs key:lang
== Go

```go
var user struct {
ID int64 `db:"user_id"`
}
err = c.QueryOne("select id as user_id from users where id = ?", 1).Scan(&user)
```

== TypeScript

```typescript
let user = await c.queryOne<{ user_id: number }>(
"select id as user_id from users where id = ?",
1,
);
```

:::

## Exec

`Exec` for SQL statement that don't return data.

::: tabs key:lang
== Go

```go
rowsAffected, err := c.Exec("update users set name = ? where id = ?", "test1", 1)
```

== TypeScript

```typescript
let rowAffected = await c.exec(
"update users set name = ? where id = ?",
"test1",
1,
);
```

:::