# Create Temporary Sqlite in Memory

**URL:** <https://www.ruby-forum.com/t/create-temporary-sqlite-in-memory/181914>\
**Category:** Rails\
**Created:** [January 20, 2010, 4:40am UTC](https://www.ruby-forum.com/t/create-temporary-sqlite-in-memory/181914 "2010-01-20T04:40:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karlshea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58956e/32.png) [@karlshea](https://www.ruby-forum.com/u/karlshea)\
**Post date:** [January 20, 2010, 4:40am UTC](https://www.ruby-forum.com/t/create-temporary-sqlite-in-memory/181914/1 "2010-01-20T04:40:21Z")

</div>

I need to create a temporary, in memory, Sqlite3 database… plus I  
want all the AR goodness to go with. Oh, and I don’t want to affect  
existing AR models or schemas.

I’m close, but I don’t know how to create a schema just for my  
temporary database so that it won’t affect other model’s schemas. In  
other words, I only want this schema/model to be active during a  
single method execution.

```
class PlsTemp < ActiveRecord::Base; end
PlsTemp.establish_connection(:adapter => "sqlite3", :database =>

```

“:memory:” )

How to I create the schema for PlsTemp?

---

<div class="post-metadata">

**Author:** ![karlshea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58956e/32.png) [@karlshea](https://www.ruby-forum.com/u/karlshea)\
**Post date:** [January 20, 2010, 7:48am UTC](https://www.ruby-forum.com/t/create-temporary-sqlite-in-memory/181914/2 "2010-01-20T07:48:47Z")

</div>

I gave up. Not sure this can even be done in AR, at least not without  
a fair amount of custom sql.

Went with creating a temporary table in production database  
(postgresql). Not as fast as sqlite/memory, but acceptable.

---

<div class="post-metadata">

**Author:** ![karlshea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/58956e/32.png) [@karlshea](https://www.ruby-forum.com/u/karlshea)\
**Post date:** [January 20, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/create-temporary-sqlite-in-memory/181914/3 "2010-01-20T19:31:07Z")

</div>

On Jan 19, 2010, at 10:47 PM, Karl S. wrote:

> I gave up. Not sure this can even be done in AR, at least not without  
> a fair amount of custom sql.
> 
> Went with creating a temporary table in production database  
> (postgresql). Not as fast as sqlite/memory, but acceptable.

Have you considered ActiveRecord::Migration? You might also look at the  
code for the db:schema:load rake task.

HTH
