Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access default Rails sqlite db?

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

like image 206
kostja Avatar asked Apr 16 '12 09:04

kostja


People also ask

How do I access SQLite database?

Open a command prompt (cmd.exe) and 'cd' to the folder location of the SQL_SAFI. sqlite database file. run the command 'sqlite3' This should open the SQLite shell and present a screen similar to that below.

How do I view a database in rails?

You can use rails dbconsole to view the database that your rails application is using. It's alternative answer rails db . Both commands will direct you the command line interface and will allow you to use that database query syntax.

What database does rails use by default?

Rails defaults to using a SQLite database when creating a new project, but you can always change it later.


2 Answers

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.

like image 84
Gazler Avatar answered Sep 25 '22 10:09

Gazler


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.

like image 29
Steve Weet Avatar answered Sep 22 '22 10:09

Steve Weet