Skip to main content

Posts

Showing posts with the label Performance

Playing with Hooks in Gorm #GolangDev

Pixabay Hello everyone, I would like to share some tricks in gorm, the Idea of this tricks is to execute a command or code statement in the middle of an ORM operation, if you ever know about trigger in the query language, then hooks is just kinda like that. Hooks could execute statement in some events such as: beforeCreate, beforeUpdate, afterCreate,  and afterUpdate . those event is similar as a trigger,  when the trigger is executed in DBMS layer, hooks are executed in the application layer. In my real case, my current company has different convention of naming database column, so when I try to implement ORM, a lot of columns such as created_at, updated_at and deleted_at can't be generated automatically. also if you have a custom UUID you could pass the value UUID generator into hooks before the insert is executed. for more detail let's jump into code : # Explanation Above code containing model struct, and several methods from gorm to serve model, TableName method used to d...

How Strict is Golang? #GolangDev

pixabay.com Hello everyone, in this occasion I would like to share about the strictness of golang. what kind of strict? let see below. Golang is the functional programming that really have concern about performance, giving limitation to prevent overuse memory is the big deal. for example, golang has a variative type of data such as int, string, boolean, float, array etc. I wonder that you are thinking about "what kind of strictness that is? its totally similar other language", YES . but golang have specification in numeric type of data such as int have int8, int16, int32, int64 . golang also have uint8, uint8, uint32 and uint64 which is its really strict you know. the following number after type of data is stand for the length. Obviously you could use the largest type of data for all the variables, but you know it could overwhelming if you put int64 in "is_valid" variable right? joking :D. golang really care about performance, because each length of v...