Simple Queries with Beego ORM
Explore how to use Beego ORM to manage database operations within Golang web applications. Understand how to insert, update, and delete records, as well as perform select queries with filtering, ordering, and pagination. This lesson provides practical knowledge for interacting with your data effectively using Beego's ORM features.
The insert, update, and delete operations
For the purpose of simplicity, we will use the following model structure throughout this lesson:
This structure represents the following:
Lines 1–5: The
Userstructure is the model for theusertable.Lines 2–4: The
Id,Name, andAgevariables represent the columnsid,nameandage, respectively.
Insert
The following code can be used to insert a row in the user table:
To insert a new record, we do the following:
Line 2: We create an instance of the
Userstruct with the desired values of the row we want to insert.Line 3: We create a new ORM object. This variable
ois used to do ORM operations.Line 4: We ...