以下の内容はhttps://takuya-1st.hatenablog.jp/entry/20120302/1330709753より取得しました。


ActiveRecord単体で、Sqliteにテーブルを作る。

ActiveRecordの単体でSQLiteにテーブルを作るとかしてみた。

データベースにテーブル作るのすらActiveRecordを使ったら楽な気がする。

  1 #!/usr/bin/env ruby
  2
  3 require 'rubygems'
  4 require 'active_record'
  5
  6 ActiveRecord::Base.establish_connection(
  7     "adapter"=>"sqlite3",
  8       "database" => "./data.sqlite"
  9 )
 10
 11 class TestCreation < ActiveRecord::Migration
 12   def self.up
 13     create_table :entries do|t|
 14       t.string :title
 15     end
 16   end
 17 end
 18
 19
 20 TestCreation.new.up
 21
 22 

結果

テーブルできた。

SQLite version 3.7.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .schema
CREATE TABLE "entries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255));
sqlite> .tables
entries
sqlite> 

できた。

アダプタ名

 18
 19 ActiveRecord::Base.establish_connection(
 20   "adapter"=>"sqlite3",
 21   "database" => "./ndl_data.sqlite"
 22 )


なんか adapter 名が sqliteから sqlite3に変わったみたい。



苦労したけどなんとか動かせたみたい。




以上の内容はhttps://takuya-1st.hatenablog.jp/entry/20120302/1330709753より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14