Open7

GoのSQLクライアントBunを試す

yulogyulog

このチュートリアルではSQLiteをIn-Memory DBで使っているので毎回消える。

sqldb, err := sql.Open(sqliteshim.ShimName, "file::memory:?cache=shared")
yulogyulog

保存されるとCreate Tableでちゃんとエラーになる。

[bun]  21:02:30.667   CREATE TABLE          8.349ms  CREATE TABLE "users" ("id" INTEGER NOT NULL, "name" VARCHAR, PRIMARY KEY ("id"))
[bun]  21:02:30.672   INSERT                5.033ms  INSERT INTO "users" ("name") VALUES ('admin') RETURNING "id"
[bun]  21:02:30.672   SELECT                     0s  SELECT "u"."id", "u"."name" FROM "users" AS "u" ORDER BY id ASC LIMIT 10
[{{} 1 admin}]
[bun]  21:02:44.559   CREATE TABLE               0s  CREATE TABLE "users" ("id" INTEGER NOT NULL, "name" VARCHAR, PRIMARY KEY ("id"))     *sqlite.Error: SQL logic error: table "users" already exists (1)
[bun]  21:02:44.566   INSERT                6.504ms  INSERT INTO "users" ("name") VALUES ('admin') RETURNING "id"
[bun]  21:02:44.566   SELECT                     0s  SELECT "u"."id", "u"."name" FROM "users" AS "u" ORDER BY id ASC LIMIT 10
[{{} 1 admin} {{} 2 admin}]