I have been building an API in Go, which I want to link to a Postgres
SQL table. I have always used NoSQL
previously but thought it would be good to try a SQL
database.
Here are my structs
type Activity struct {
Activity string `json:"activity"`
Payload Payload `json:"payload"`
}
type Payload struct {
UserID string `json:"userId"`
Duration int `json:"duration"`
Type string `json:"type"`
Date int `json:"date"`
}
Based on the above I thought it would be good to have a table for payload which was made via the following query.
CREATE TABLE payload (
userid SERIAL PRIMARY KEY,
duration INT,
type TEXT,
date INT
);
and then created the activity table like the following:
CREATE TABLE activity (
activity TEXT PRIMARY KEY
SELECT userid, duration, type, date
FROM payload;
);