How to access default Rails sqlite db?

69,012

Solution 1

You have neglected to mention the OS you are using.

One way is to use the sqlite3 command in your terminal.

sqlite3 db/development.sqlite3

However, for things like inspecting your rows, you would be better using a rails console.

rails c
> User.all # Where user is your model.

NOTE: Do not change your DB schema directly through sqlite3, something you may be used to if you come from a different web stack background. This is because the next time you run the migrations, the state will be different to what rails expects.

Solution 2

Rails 3 provides a generic command for accessing the correct database client and pass in the name of the correct database for your current environment. This command is rails dbconsole which can be shortened to rails db

$ rails db
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> 

This command does not offer much more than Gazler's answer and in fact his advice to use the console is good advice however the plus side for this method is that it will use the correct client if your DB is different in other environments.

Solution 3

use

SQLite> .tables

this will give you the list of all tables exist in the selected database

@@to activate the consol

SQLite> rails dbconsole

@@to show tables

SQLite>.tables

@@ to show all rows in a table

SQLite> select * from posts

Solution 4

There is a great application to browse sqlite3 databases. SQLite Database Browser.

P.S. You mentioned that you are using Aptana studio. I have started my RoR learning with this IDE as well but later have discovered Sublime Text and never wanted to use anything else since, I advise you to check it out.

Cheers

Solution 5

To view data on DB, I used an SQLite client called DB Browser for SQLite,here is the link

There is a Linux version of this app too. There should be a database file with sqlite extension on db directory of the app. On DB Browser, select Open Database option and choose that file and you should be able to view the data.

Share:
69,012
kostja
Author by

kostja

We are here to learn :) Works and plays with scala, kafka, data, linux

Updated on July 08, 2022

Comments

  • kostja
    kostja almost 2 years

    I would like to view the data in my DB while developing with Rails (actually in all 3 of them development, test and production). I have not touched the configs, so it should be easy, but I was not able to find any usable info.

    I have no idea what the connection string could be or where to enter it, since Aptana (v.3) seems to lack the good old data source explorer view I know from Eclipse. Could someone point me into the right direction?

    EDIT: I am working on linux - Mint 12