How to access default SQL Rails sqlite?

I would like to see the data in my database during development using Rails (in fact, in all three of them there is development, testing and production). I did not deal with configurations, so it should be easy, but I could not find useful information.

I have no idea what the connection string is or where to enter it, since Aptana (v.3) does not seem to have a good old view of the data source that I know from Eclipse. Can someone point me in the right direction?

EDIT: I am working on linux - Mint 12

+54
ruby-on-rails sqlite ruby-on-rails-3 aptana
Apr 16 '12 at 9:30
source share
8 answers

You neglected to mention the operating system you are using.

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

 sqlite3 db/development.sqlite3 

However, for things like checking your lines, you better use the rails console.

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

NOTE. Do not change your database schema directly through sqlite3, which you can get used to if you came from a different web stack background. This is due to the fact that the next time you start the migration, the state will be different from the expected rails.

+80
Apr 16 2018-12-12T00:
source share

Rails 3 provides a generic command to access the correct database client and passes the name of the correct database to your current environment. This 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 on using the console is good advice, but the plus side of this method is that it will use the right client if your database is different in other environments.

+41
Apr 16 '12 at 10:21
source share

use

 SQLite> .tables 

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

@@ to activate the console

 SQLite> rails dbconsole 

@@ to display tables

 SQLite>.tables 

@@ to show all rows in the table

 SQLite> select * from posts 
+8
Jul 25 '13 at 16:55
source share

There is a great application for viewing sqlite3 databases. SQLite Database Browser .

PS You mentioned that you are using Aptana Studio. I also started learning RoR with this IDE, but later discovered Sublime Text and never wanted to use anything else since then, I advise you to check it out.

Greetings

+6
Aug 30 '13 at 7:54 on
source share

You can have online access to your database if you use activeadmin .

Just add the activeadmin-sqlpage gem :

 gem 'activeadmin-sqlpage' 

Create an activeadmin page:

 # file app/admin/sql.rb ActiveAdmin::SqlPage::register 

Reboot the server. Then go to the admin panel and go to the SQL menu. Type any sql command and press Ctrl+Enter or Submit .

0
Apr 01 '17 at 16:34 on
source share

Open a terminal and enter this command. This will open the rails console to query the database.

 rails c 

To get a list of all the models, you can use the following command

 ActiveRecord::Base.connection.tables 

example: ["schema_migrations", "ar_internal_metadata", "categories", "Points"]

From the list of models you can get the first, last or all entries.

 Category.all 
0
Dec 27 '17 at 4:28
source share

If you are using the RubyMine IDE, you can access the sqllite data source from there. You can execute queries or edit data in the database using the graphical interface.

0
Jul 28 '18 at 11:37
source share

To view the data in the database, I used a SQLite client called DB Browser for SQLite, there is a link

There is also a Linux version of this application. There must be a sqlite database file in the application db directory. In the database browser, select the option "Open database" and select this file, and you can view the data.

0
Aug 08 '19 at 4:58
source share



All Articles