Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zakirkun committed Dec 23, 2024
1 parent 7b6409d commit 7b08981
Showing 1 changed file with 59 additions and 9 deletions.
68 changes: 59 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Toki is a fast and efficient SQL query builder for Go that helps you build SQL s
- 🚀 High-performance query building
- 🔒 Automatic placeholder conversion (? to $1, $2, ...)
- 💾 Memory pooling for better performance
- 📦 Transaction support
- 🎯 Dynamic query construction
- 🛡️ SQL injection prevention
- 📦 Transaction support with automatic rollback
- 🎯 Fluent interface for query construction
- 🛡️ Secure parameter binding and SQL injection prevention
- 📊 Structure binding support
- ⚡ Memory efficient operations
- 🔍 Expression support
- 🔍 Expression and Raw query support

## Installation

Expand Down Expand Up @@ -73,6 +73,7 @@ func main() {

### Query Building

### SELECT Queries
```go
// SELECT query
builder.
Expand All @@ -81,12 +82,16 @@ builder.
Where("age > ?", 18).
AndWhere("status = ?", "active").
OrderBy("created_at DESC")

```
### INSERT Queries
```go
// INSERT query
builder.
Insert("users", "name", "email").
Values("John Doe", "[email protected]")

```
### Update Queries
```go
// UPDATE query
builder.
Update("users").
Expand All @@ -95,12 +100,23 @@ builder.
"updated_at": "NOW()",
}).
Where("id = ?", 1)

```
### Delete Queries
```go
// DELETE query
builder.
Delete("users").
Where("status = ?", "inactive")
```
### Raw Queries
```go
builder.Raw(`
SELECT u.*, p.name as profile_name
FROM users u
LEFT JOIN profiles p ON p.user_id = u.id
WHERE u.created_at > $1
`, time.Now().AddDate(0, -1, 0))
```

### Transaction Support

Expand Down Expand Up @@ -187,6 +203,41 @@ query := builder.
// Automatically converts to $1, $2, etc. for PostgreSQL
// SELECT * FROM users WHERE age > $1 AND status = $2
```
## Best Practices

1. **Use Transactions for Multiple Operations**
```go
tx, _ := toki.Begin(db)
defer tx.Rollback()
// ... perform operations
tx.Commit()
```

2. **Always Close Rows**
```go
rows, err := stmt.Query()
if err != nil {
return err
}
defer rows.Close()
```

3. **Use Parameter Binding**
```go
// Good
Where("id = ?", id)

// Bad
Where(fmt.Sprintf("id = %d", id))
```

4. **Utilize Structure Binding**
```go
type User struct {
ID int `db:"id"`
Name string `db:"name"`
}
```

## License

Expand All @@ -198,5 +249,4 @@ Contributions are welcome! Please feel free to submit a Pull Request.

## Support

If you have any questions or need help, please open an issue in the GitHub repository.

If you have any questions or need help, please open an issue in the GitHub repository.

0 comments on commit 7b08981

Please sign in to comment.