0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

データベースの中身をrails dbconsoleで確認する方法

Posted at
1 / 2

記事の内容

ターミナルでデータベースの中身を確認する。

dbのコンソールを起動する

まずはコンソールを起動する。

$ rails dbconsole

コンソールが起動。

sqlite>

コンソールからデータベースの内容を確認

テーブル一覧を表示。

sqlite> .table
ar_internal_metadata  schema_migrations     users 


指定したテーブルの構造を確認。

.schema users
CREATE TABLE IF NOT EXISTS "users" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar NOT NULL, "crypted_password" varchar, "salt" varchar, "last_name" varchar NOT NULL, "first_name" varchar NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email");


ちなみに、テーブルを指定しないと全テーブルを確認できます。

.schema
CREATE TABLE IF NOT EXISTS "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY);
CREATE TABLE IF NOT EXISTS "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
CREATE TABLE IF NOT EXISTS "users" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar NOT NULL, "crypted_password" varchar, "salt" varchar, "last_name" varchar NOT NULL, "first_name" varchar NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
CREATE TABLE sqlite_sequence(name,seq);
CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email");


個別のSQL文も打つことができる。

sqlite> select * from users;
1|e@e|||e|e|2022-05-13 18:03:09.993057|2022-05-13 18:03:09.993057


コンソールを終了。

sqlite> .quit
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?