err:=db.QueryRow("SELECT id, name, age, role FROM users WHERE id = "+id).Scan(&user.ID,&user.Name,&user.Age,&user.Role)
iferr!=nil{
returnuser,err
}
returnuser,nil
}
typePostsstruct{
IDint
Titlestring
Contentstring
Langstring
}
funcaddDummyPosts(db*sql.DB){
_,err:=db.Exec("CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY, title TEXT, content TEXT, lang TEXT)")
iferr!=nil{
panic(err)
}
// Inserting English dummy posts
_,err=db.Exec("INSERT INTO posts (id, title, content, lang) VALUES (1, 'The Joy of Programming', 'Programming is like painting a canvas with logic.', 'en')")
iferr!=nil{
panic(err)
}
_,err=db.Exec("INSERT INTO posts (id, title, content, lang) VALUES (2, 'A Journey Through Code', 'Every line of code tells a story.', 'en')")
iferr!=nil{
panic(err)
}
// Inserting a Spanish dummy post
_,err=db.Exec("INSERT INTO posts (id, title, content, lang) VALUES (3, 'La belleza del código', 'Cada función es un poema en un mar de algoritmos.', 'es')")