February 2018
Intermediate to advanced
340 pages
9h 43m
English
DROP TABLE IF EXISTS post; CREATE TABLE post ( ID serial, TITLE varchar(40), CONTENT varchar(255), CONSTRAINT pk_post PRIMARY KEY(ID) ); SELECT * FROM post;
package main import ( "database/sql" "fmt" _ "github.com/lib/pq" ) const sel = "SELECT * FROM post;" const trunc = "TRUNCATE TABLE post;" const ins = "INSERT INTO post(ID,TITLE,CONTENT) VALUES (1,'Title 1','Content 1'), (2,'Title 2','Content 2') " func main() { db := createConnection() defer db.Close() _, err := db.Exec(trunc) if err != nil { panic(err) } fmt.Println("Table ...Read now
Unlock full access