Write Raw Queries and Use Query Builder

Learn to write raw SQL queries and use Query Builder to build complex queries using Beego ORM.

Writing raw SQL queries

In Beego ORM, we can write raw SQL queries using the Raw method. This method takes a raw SQL query as a string. The Raw method is chained with methods like QueryRows, QueryRow, and Exec to execute the query and retrieve the results.

Here’s an example of how to use the Raw method to execute a raw SQL query that selects all records from a users table:

Get hands-on with 1400+ tech skills courses.