GoLangでSQLiteを使いたいので、Installする。
$ ls -l /mnt2/slackware64/*/*sqlite*.txz
\-rw-r–r– 1 root root 1030596 1月 7 2022 /mnt2/slackware64/ap/sqlite-3.37.2-x86_64-1.txz
$ sudo installpkg /mnt2/slackware64/ap/sqlite-3.37.2-x86_64-1.txz
(メモ省略)
$ grep -E ‘bin|lib’ /var/log/packages/sqlite-3.37.2-x86_64-1 | sed s@^@/@ | xargs ldd | grep found
(依存の不足は無かった)
SQLiteは組み込み式 DBなので、Goのライブラリ側で用意してあるはずなので、要らなかった?。
DBを作成したり、DBの中身を見るコマンドとかで使うか。
以前作った、お問い合わせTableと同じ様なのを、phpMyAdminを見ながら作ってみる。
$ sqlite3 smp001.db
SQLite version 3.37.2 2022-01-06 13:25:41
Enter “.help” for usage hints.
sqlite> create table if not exists mst_message ( code integer primary key autoincrement, name text not null, email text not null, message text not null);
sqlite> .tables
mst_message
sqlite> insert into mst_message ( name, email, message) values (‘test’, ‘test@test.jp’, ‘this is test’);
sqlite> select * from mst_message;
1|test|test@test.jp|this is test
sqlite> .exit
Go側にgo-sqlite3パッケージをインストールする。
$ export PATH=$PATH:/usr/local/go/bin
$ export GOPATH=~/go
$ go mod init example.net/myproj/oldcygwin/practice800/practice820
go: creating new go.mod: module example.net/myproj/oldcygwin/practice800/practice820
go: to add module requirements and sums:
\ go mod tidy
$ go get github.com/mattn/go-sqlite3
go: downloading github.com/mattn/go-sqlite3 v1.14.22
go: added github.com/mattn/go-sqlite3 v1.14.22
参考AI:
https://chat.openai.com/auth/login
以下のGo言語について、SQLiteを使う記述に変更
SQLiteで、primary key をコマンドで設定する方法は?
テーブルの内容を表示するコマンドは?
参考URL:
sqlite3 コマンド db作成、でググった:
https://www.javadrive.jp/sqlite/database/index1.html
sqlite3 コマンド、でググった:
https://qiita.com/ChiakiYamaoka/items/b7c7863688d6f23c0501
インストール時の説明:
# sqlite (simple, self contained database engine)
# SQLite is a small C library that implements a self-contained,
# embeddable, zero-configuration SQL database engine.
# The SQLite distribution comes with a standalone command-line access
# program (sqlite) that can be used to administer an SQLite database
# and which serves as an example of how to use the SQLite library.
# Homepage: http://www.sqlite.org/