cabalでローカルにあるライブラリを使う
課題
- ローカルに自作ライブラリのソースコードがある。
- ライブラリ側の変更はない仮定(安定している仮定)。
- そのライブラリを使うプログラムをローカルで作りたい。
- ライブラリのソースコードとディレクトリは別にするが、cabalプロジェクトを作る。
- ライブラリ側はlibraryディレクトリ配下、プログラムはsrc配下のようにする。
- ライブラリ側のコードも一緒にコンパイルされるので、ビルドに時間がかかる。 ⇨ なんとかしたい
解決策
- ライブラリ単独でcabalプロジェクトにして、それをプログラム側のcabalプロジェクトにインストールする。
やり方
- ライブラリ用のcabalプロジェクトを作成する。
> cabal sandbox init などなど
name: mylibrary version: 0.1.0.0 省略 library exposed-modules: Foo.Bar.X , Foo.Bar.Y , Foo.Bar.Z , などなど
- ライブラリモジュールを作成する(ビルドする)。
> cabal build
- 上記のライブラリを利用するcabalプロジェクトを作成する。まずは、ライブラリを意識せずにプロジェクトを作成する。
> cabal sandbox init いろいろ
- ライブラリプロジェクトを取り込む。
> cabal sandbox add-source ライブラリがあるパス(のcabalファイルの親ディレクトリのパス)
- cabalファイルの依存関係の指定をする。
executable myprogram main-is: Main.hs other-extensions: BangPatterns, DeriveDataTypeable, DeriveGeneric, FlexibleInstances, MultiParamTypeClasses build-depends: base >=4.9 && <4.10 その他いろいろ , mylibrary <-- ここにライブラリ名を追加
- インストール
> cabal install
- 再度やり直したいときは、取り込んだライブラリプロジェクトをいったん削除する。その後、もう一度インストールをする。
> cabal sandbox delete-source ライブラリがあるパス(のcabalファイルの親ディレクトリのパス)
MySQLのSample Databaseの設定
sample data
https://dev.mysql.com/doc/index-other.html
word_x-db
Download and unzip
shell> wget http://downloads.mysql.com/docs/world_x-db.zip shell> unzip world_x-db.zip
Read instruction
shell> less world_x-db/README.txt
Connect to MySQL:
shell> mysql -u root -p
Load the file:
mysql> SOURCE /tmp/world_x-db/world_x.sql;
sakila-db
Download and unzip
shell> wget http://downloads.mysql.com/docs/sakila-db.zip shell> unzip sakila-db.zip
Connect to MySQL:
shell> mysql -u root -p
Load the file:
mysql> SOURCE example-databases/sakila-db/sakila-schema.sql mysql> SSOURCE example-databases/sakila-db/sakila-data.sql
Reference
https://dev.mysql.com/doc/sakila/en/sakila-installation.html
menagerie-db
download and unzip
shell> wget http://downloads.mysql.com/docs/menagerie-db.zip shell> unzip menagerie-db.zip
Connect to MySQL and make tables
shell> mysql -u root -p mysql> SOURCE example-databases/menagerie-db/cr_pet_tbl.sql mysql> SOURCE example-databases/menagerie-db/cr_event_tbl.sql
Disconnect mysql, cd and load data
shell> cd example-databases/menagerie-db shell> mysql menagerie --local_infile=1 -u root -p < load_pet_tbl.sql shell> mysqlimport --local menagerie event.txt
Reference
ysql-connector-java-6.0.6のサンプル実行
$javac -cp .:mysql-connector-java-6.0.6-bin.jar DevApiSample.java $java -cp .:mysql-connector-java-6.0.6-bin.jar:lib/protobuf-java-2.6.0.jar DevApiSample Connected! Default schema is: Schema(foo) Currently reading Effi Briest on page 42 Currently reading Effi Briest on page 42 Number of books in collection: 0