# Read-only access to database?

**URL:** <https://www.ruby-forum.com/t/read-only-access-to-database/65786>\
**Category:** Rails\
**Created:** [February 11, 2006, 9:12am UTC](https://www.ruby-forum.com/t/read-only-access-to-database/65786 "2006-02-11T09:12:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@cal](https://www.ruby-forum.com/u/cal)\
**Post date:** [February 11, 2006, 9:12am UTC](https://www.ruby-forum.com/t/read-only-access-to-database/65786/1 "2006-02-11T09:12:33Z")

</div>

I have a model (Query) which I use to, of all things, query the  
database. This  
is to enable raw SQL access. I want to ensure that db access using this  
model  
is read-only. Short of checking the sql query for ‘insert’ and ‘drop’  
and  
‘update’, is there a more rails-like way of doing this in my  
app/models/query.rb  
itself?

Thanks in advance,

cal

---

<div class="post-metadata">

**Author:** ![cal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@cal](https://www.ruby-forum.com/u/cal)\
**Post date:** [February 11, 2006, 3:56pm UTC](https://www.ruby-forum.com/t/read-only-access-to-database/65786/2 "2006-02-11T15:56:32Z")

</div>

On 2/10/06, cal [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a model (Query) which I use to, of all things, query the database. This  
> is to enable raw SQL access. I want to ensure that db access using this model  
> is read-only. Short of checking the sql query for ‘insert’ and ‘drop’ and  
> ‘update’, is there a more rails-like way of doing this in my app/models/query.rb  
> itself?

You could have it use a separate database connection that logs in as a  
user with read-only access in your database.

---

<div class="post-metadata">

**Author:** ![cal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@cal](https://www.ruby-forum.com/u/cal)\
**Post date:** [February 13, 2006, 7:23am UTC](https://www.ruby-forum.com/t/read-only-access-to-database/65786/3 "2006-02-13T07:23:49Z")

</div>

How can we use seperate db connection since there’s only 1 account per  
environment? Does anyone already try this?

–  
Tirta K. Untario

---

<div class="post-metadata">

**Author:** ![cal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@cal](https://www.ruby-forum.com/u/cal)\
**Post date:** [February 13, 2006, 7:28am UTC](https://www.ruby-forum.com/t/read-only-access-to-database/65786/4 "2006-02-13T07:28:26Z")

</div>

Models can be set to readonly. View the docs.

Bob S.  
[http://www.railtie.net/](http://www.railtie.net/)
