I'm trying to implement a function in Go where I need to connect to a sqlite database. This DB has more than one model, and a superior suggested me using the GORM lib. It seems the program detects by name the table I'm attempting to access, but it always returns zero values (numerical attributes) or empty strings.
My first attempt was modelling the schema wihout struct tags, however it was the first time I got the problem. Then I tried using struct tags using the 'db' preffix, specifying the name of every attribute in SQLITE, but nothing changed. After that, I applied struct tags with the 'sql' preffix... Again nothing happened, and got the same problem. As a last attempt I changed the preffix to 'gorm', but got the problem once more. Afterwards, I deleted all the struct tags and left just the struct tag corresponding to the primary key (ID).
I don know what to do but to give GORM up and use another library... :(
The schema in SQLite
TABLE COMPANIES(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
The model I coded
type Company struct {
gorm.Model
ID int `gorm:"PRIMARY_KEY"`
Name string
Age int
Address string
Salary float32
}
fmt.Println(db.HasTable("COMPANIES"))//It returns "true"
db.First(&company)
fmt.Println(company)
What is printed in console:
{{0 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC <nil>} 0 0 0}
[2019-09-11 11:49:09] no such column: companies.deleted_at
The weird thing is, the table is actually populated, and has neither zero values nor empty strings.