alex brie . net

bloghez din 2003 despre mine, internet, prieteni si altele.

  • Blog
  • About
  • Contact
  • Articole preferate
  • Publicitate
  • Blogs
« Salvati un presedinte!
V1 »

Setting up Rails and SQLITE

April 25th, 2007 |

If you are interested in web, databases and the like then you probably already heard of SQLITE. If not, here’s a quick intro
SQLITE is a database engine that uses just one file per database. It’s tiny, simple to use and, most importantly, very easy to use with Ruby on Rails. All you need is the sqlite ruby gem, which is already included in most Ruby installations.

What is sqlite3? Nothing much than a newer and better version of sqlite. You should use it instead of sqlite if you have the chance.

How do you set it up in Rails?
Let’s say you want to make your own database-driven Rails application. Mysql is a big download, a bit difficult to install, etc. Plus, you don’t really need it; you just want a tiny sql database engine that works with Rails, so you can develop and test your application.
Nothing easier: if not already installed on your machine, then you download and install sqlite3.
Then you make sure you have the latest sqlite bindings in place : gem install sqlite3 .

Hmm.. what else?

oh… the config/database.yml file.

development:
    adapter: sqlite3
    database: db/development.sqlite3

test:
    adapter: sqlite3
    database: db/test.sqlite3

production:
    development

Well now; you are set up. Just go ahead, create your database structure. How? Edit db/schema.rb and start adding tables definitions in a ruby syntax; something like this:


ActiveRecord::Schema.define do

  create_table "users", :force => true do |t|
    t.column :login, :string, :limit => 80
    t.column :cryptpassword, :string, :limit => 40
    t.column :email, :string, :limit => 100
    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end

  create_table :article, :force => true  do |t|
      t.column :title, :string
      t.column :created_at, :datetime
      t.column :updated_at, :datetime
      t.column :content, :text
  end
end

Warning! Back up this file also to schema_backup.rb

To import this schema in your database, all you have to do is run rake db_schema_import

You see? All set now. You can start generating your scaffolding and code away.

How to take your data OUT of sqlite?
If at some point in the future, you want to get your data OUT of the sqlite3 database, all you have to do is a sqlite3 dump:
run

sqlite3 db/development.sqlite3
.output my_sql_dump.sql
.dump
.exit

PS. I learned about the commands to use by peeking at sqlite3’s help over here
You’ll have to remove some of the lines at the beginning and the end of the generated my_sql_dump.sql file. But the result is a SQL file that can be later imported into MYSQL or other SQL database engine, via classic import commands.

Wel… wasn’t this easy? I sure did learn a lot. :)

Pe vremea asta…

  • 2007: Salvati un presedinte!
  • 2007: Gata! De ajuns!

Daca esti nou pe aici, nu uita sa te abonezi la feedul meu RSS rss feed. Iti multumesc pentru vizita!

Articole inrudite

  • Fara articole inrudite.


Postata in Rails, Ruby, Tutorials | RSS 2.0 feed comentarii | Comenteaza; Trackback.

2 Responses to “Setting up Rails and SQLITE”

  1. Gravatar David:
    May 1st, 2007 at 12:48 am

    Very helpful article, thanks

  2. Gravatar Simeon:
    June 6th, 2007 at 12:54 am

    Thanks for your article. I just tried to install sqlite3 and ended up needing to run this instead

    gem install sqlite3-ruby

    But otherwise the instructions were great!

Leave a Reply

  • Pe vremea asta...

    • 2007: Salvati un presedinte!
    • 2007: Gata! De ajuns!
  • Despre Alex Brie

    View Alexandru Brie's profile on LinkedIn

    Bloger pasionat din septembrie 2003.
    Software engineer; master in cercetare algoritmica la Ecole Polytechnique Paris; a lucrat in Paris in software bursier.

    Inapoi in Romania din 2006, programeaza Ruby on Rails pentru un startup american, este consultant independent, blogger si antreprenor cu diverse proiecte online
    [afla mai multe..]

    Aboneaza-te RSS(Romanian)

      
    Acum te poti abona si prin email.

    Subscribe(English)

  • Urmareste-ma si pe Twitter

    • Recomand

      cele mai tari stiri de pe blogurilejurnal de fapte bune

    • Users Online

      • 12 Users Online
      • Users: 12 Users
    • Comentarii recente

      • Cu ce masini m-am dat in Romania | Cafeina.ro on On/Off road adventure - Concluzii Drive Test SSang Yong Rexton
      • farouk on Beginner’s blogging guide - How to bring traffic to your blog
      • limpede on Berea e placere ?!
      • Alsaru on Patine cu rotile - wishlist 1
      • Ibdreamy.com » Blog Archive » Twitter Apps, Plugins and Tools on TwitterYM - tiny ruby Yahoo Messenger status Twitter updater
      • Alex on Berea e placere ?!
      • Gelu on Berea e placere ?!
      • Skandalouz on Bucurie pura
      • Andrei on Bucurie pura
      • Alex on Cum voi castiga eu la loto :D
      • Alex on 10 Ruby programming tips you should already know
      • Piku on 10 Ruby programming tips you should already know
      • Anca on Caut Crocs
      • Alex on Hai in blogroll si poti fi Blogul saptamanii, pe Alex Brie . net
      • Alex on Capac de canal la Sibiu
    • bloguri care ma citesc

      • Andrei.Voce.ro
      • Avram Seby
      • Blog ul lui Mage - mai acid decat clorhidricul
      • Blogatu
      • Bogdan’s Weblog
      • Costinu Rgbdesigners
      • cotofana.RO
      • dEsign.101
      • Dowel
      • Insemnari.ro
      • Kappacelu
      • LIMPEDE - blog
      • Mihai Nasaudean Blog
      • serban.us
      • www.liveMag.ro
    • Archives

    • TLA

      • party supplies
    • Categories

      • Blog (1320)
        • carcoteli (4)
        • English (14)
        • evenimente (6)
        • FILMS (33)
        • French (3)
        • fun (57)
        • intrebari (5)
        • jocuri (5)
        • masini (1)
        • masini (1)
        • matematica (1)
        • PHOTO (147)
          • desene (12)
          • flori (2)
          • oua rosii (1)
        • Projects (81)
          • business (31)
          • ROSI (12)
        • Promo (3)
        • Romanian (118)
          • aici (49)
          • repat (33)
        • scurte (10)
        • Software (23)
          • .mac (20)
        • stiati ca (4)
        • Stiri IT Media si Internet (51)
          • yahoo (1)
        • Technicalities (66)
        • Web (460)
          • links (150)
          • Memes (54)
          • video (58)
      • dev (21)
        • Open Source (1)
        • Rails (9)
        • Ruby (8)
        • Textpattern (2)
        • Tips and Tricks (9)
        • Tutorials (7)
        • Wordpress (6)
      • iPhone (7)
      • opinii (1)
      • recenzii (9)
      • tutoriale (1)
      • Words (133)
        • essays (32)
        • Politice (44)
        • vss[very short stories] (5)
    .mac aici antreprenoriat Apple Basescu Blog blogger bloggeri blogging blogosfera bloguri blogvertising booq bucuresti business carti ceausescu cleopatra stratan comics concurs conferinte Desktop-TD Digg evenimente feedburner FILMS flash fun ganduri Google internet intrebari iPhone iread IT jocuri Leopard links linkuri Manafu marketing marketonline market online masini mema Memes Microsoft muzica myblog Netcamp netstart olimpiade online oprescu OSX personal PHOTO politica Politice poze presa programare proiecte publicitate Rails repat review rexton roblogfest Romania Romanian ROSI Ruby script seo snippet software spam ssang yong stiri Techmeme testdrive Tips and Tricks triburi triburile tutorial Tutorials twitter Utopia viata viata mea video viral vodafone Web Wordpress Words yahoo yahoo messenger youtube

    Entries (RSS) and Comments (RSS).
    Theme inspired by CrunchNotes, by Alex Brie.

    Copyright © 2005-2008 alex brie . net. Unele articole pot contine tematici sau linkuri sponsorizate. Opiniile si idele sunt intodeauna ale autorului, care le imbratiseaza si le sustine.