009. 在 terminal 查看数据库(sqlite3) - cwy007/tips-and-skills GitHub Wiki

1. 终端 terminal 上演示

 ✘ cwy@MPro ⮀ ~/agile-web-dev-with-rails/cwyfiles/work/depot ⮀ ⭠ master± ⮀ sqlite3 -line db/development.sqlite3
SQLite version 3.19.3 2017-06-27 16:48:08
Enter ".help" for usage hints.
sqlite> select * from line_items;
        id = 1
product_id = 1
   cart_id =
created_at = 2017-12-19 13:49:44.863691
updated_at = 2017-12-19 13:52:19.175933
  quantity = 2
  order_id = 1
sqlite> select * from orders;
        id = 1
      name = chan
   address = 河南省开封市
     email = [email protected]
  pay_type = Purchase order
created_at = 2017-12-19 13:52:19.173757
updated_at = 2017-12-19 13:52:19.173757
sqlite> .quit
 cwy@MPro ⮀ ~/agile-web-dev-with-rails/cwyfiles/work/depot ⮀ ⭠ master± ⮀

source: book -- << agile web development with rails 4 >>

2. 用到的指令

sqlite3 -line db/development.sqlite3

select * from carts;
select * from line_items;

.quit

3. 查看表单对应的 sql

在终端输入
sqlite3 db/development.sqlite3 ".schema orders"

得到的结果
CREATE TABLE IF NOT EXISTS "orders" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "address" text, "email" varchar, "pay_type" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);