Simple Queries with Beego ORM
Learn to write simple queries using Beego ORM including insert, update, delete, and retrieval.
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 ...