LoginSignup
46

More than 5 years have passed since last update.

RailsのローカルでSQLiteを使う時

Last updated at Posted at 2016-09-07

RailsのローカルでSQLiteを使う

Railsアプリケーションを触っている時に本番環境はPostgreSQLだけど
ローカルはSQLiteだったって時に

接続する

$ sqlite3 db/development.sqlite3

もしくは

$ rails db

で接続できます!

データベース一覧

sqlite> .databases

これでデータベースの一覧を確認

テーブル一覧

sqlite> .tables

これでテーブル一覧を取得

SQL文

sqlite> select * from user;

もちろんSQL文もそのまま打てます!

スキーマ表示

sqlite> .schema users 

スキーマのデーブルも確認できます!

テーブルの中のカラム確認

sqlite> PRAGMA TABLE_INFO(TABLE_NAME); 

テーブルのカラムを確認できます!

終了

sqlite> .exit

これで終了

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46