package main import ( "fmt" "github.com/QuerySpec/Database" ) func main() { q := Database.NewSelectQuery("users") q.AddColumn("id") q.AddColumn("name") fmt.Println(q.ToString()) }
package main import ( "fmt" "github.com/QuerySpec/Database" ) func main() { q := Database.NewSelectQuery("users") q.AddColumn("id") q.AddColumn("name") q.AddWhereClause("id = ?", 1) fmt.Println(q.ToString()) }
package main import ( "fmt" "github.com/QuerySpec/Database" ) func main() { q := Database.NewSelectQuery("users") q.AddColumn("id") q.AddColumn("name") q.AddWhereClause("id = ?", 1) rows, err := q.Exec() if err != nil { fmt.Println("Error:", err) } defer rows.Close() for rows.Next() { var id int var name string rows.Scan(&id, &name) fmt.Println(id, name) } }This code creates a SELECT query on the "users" table, adds two columns ("id" and "name") to the query, adds a WHERE clause to filter the results to only include records with an "id" of 1, and then executes the query. The results are retrieved using `rows.Next()` and `rows.Scan()`, and then printed to the console. The QuerySpec Database package is a third-party library available on GitHub (https://github.com/QuerySpec/Database).