<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Databases One of the most asked questions I get about web development in Go is how toconnect to a SQL database. Thankfully, Go has a fantastic SQL package in thestandard library that allows us to use a whole slew of drivers for differentSQL databases. In this example we will connect to a SQLite database, but thesyntax (minus some small SQL semantics) is the same for a MySQL or PostgreSQLdatabase. ~~~ package main import ( "database/sql" "fmt" "log" "net/http" _ "github.com/mattn/go-sqlite3" ) func main() { db := NewDB() log.Println("Listening on :8080") http.ListenAndServe(":8080", ShowBooks(db)) } func ShowBooks(db *sql.DB) http.Handler { return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { var title, author string err := db.QueryRow("select title, author from books").Scan(&title, &author) if err != nil { panic(err) } fmt.Fprintf(rw, "The first book is '%s' by '%s'", title, author) }) } func NewDB() *sql.DB { db, err := sql.Open("sqlite3", "example.sqlite") if err != nil { panic(err) } _, err = db.Exec("create table if not exists books(title text, author text)") if err != nil { panic(err) } return db } ~~~ ## Exercises 1. Make use of the `Query` function on our `sql.DB` instance to extract a collection of rows and map them to structs. 1. Add the ability to insert new records into our database by using an HTML form. 1. `go get github.com/jmoiron/sqlx` and observe the improvements made over the existing database/sql package in the standard library.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看