What do I need to do for DataMapper to have a persistent sqlite database?

Here is what I use to create my database:

DataMapper.setup(:default,"sqlite://my.db")

   class Model1

      property :some_prop,String
      ...
      property :other_prop,String
   end

   DataMapper.auto_upgrade!

I use this in combination with Sinatra. Everything is fine, while the script is running, I can use my objects in normal mode. However, I do not see the file my.dbon disk, and every time I restart the application, I start from scratch, without any objects.

What am I doing wrong?

+3
source share
2 answers

Try putting the full path there (note that there are three slashes):

DataMapper.setup(:default, "sqlite:///path/to/my/database/my.db")

Then you should see my.dbin the section/path/to/my/database/

+3
source
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/my.db")
# your schema

DataMapper.finalize
DataMapper.auto_upgrade!

Also see docs.

0
source

Source: https://habr.com/ru/post/1786445/


All Articles