Getting Started
Request handling
- Routing
- Action Controller
- Resources
- Context
- Request Binding
- Middleware
- Error Handling
- Sessions
- Cookies
Frontend
Database
- Getting started with Pop
- Soda CLI
- Database Configuration
- Buffalo Integration
- Models
- Generators
- Migrations
- Fizz
- Mutations
- Querying
- Raw Queries
- Callbacks
- Scoping
- Associations and Relationships
- One to one associations
- One to many associations
Guides
- API Applications
- File Uploads
- Background Job Workers
- Mailers
- Tasks
- Plugins
- Local Authentication
- Third Party Authentication
- Events
- Go Modules
- Localization
- Logging
- Template Engines
- Testing
- Videos
Deploy
Raw Queries
Database
Raw Queries
Sometimes you’ll need to write a custom query instead of letting Pop generate it for you. In this chapter, you’ll learn how to write raw SQL queries using Pop.
Writing a Raw Query
Select
player := Player{}
q := db.RawQuery("SELECT * FROM players WHERE id = ?", 1)
err := q.Find(&player, id)
Update
err := db.RawQuery("UPDATE players SET instrument = ? WHERE id = ?", "guitar", 1).Exec()
Delete
err := db.RawQuery("DELETE FROM players WHERE id = ?", 1).Exec()
Tokens Syntax
With RawQuery
, you can continue to use the ?
tokens to secure your input values. You don’t need to use the token syntax for your underlying database.