Closing a DataMapper DB Connection

my rails application creates many small sqlite databases using DataMapper. After saving the data, the .sqlite file must be downloaded on the remote server and destroyed locally.

My question is how to get DataMapper to close the .sqlite db connection and free repo memory? An application must generate many databases, so it is important to conserve server resources.

Just because I googled DataObjects::Pooling.pools.each do {|pool| pool.dispose} which is completely unacceptable to me, I think because it closes all the DataMapper connections, however, multiple databases can be created in parallel threads, and I also want to destroy the DataMapper repository.

Sorry for my English.

+3
source share
2 answers

It is also DataMapper::Repository.adaptersa hash of the current repository objects. You can dig there to get to the connections.

+2
source

I do not know what a good way to do this. However, this discussion does matter:

http://www.mail-archive.com/ datamapper@googlegroups.com /msg02894.html

You can apparently resume the connection using DataMapper.setup(), but it seems that closing the connections is handled automatically.

However, perhaps these observations will help:

You can save the link to the adapter, for example

a = DataMapper.setup(:default, "sqlite:db/development.sqlite3")

Viewing this object shows that the path has been saved, implying that it is for this particular connection, and not as a SQLite adapter as a whole, or such:

p a

#<DataMapper::Adapters::SqliteAdapter:0x00000001aa9258 @name=:default, @options={"scheme"=>"sqlite", "user"=>nil, "password"=>nil, "host"=>nil, "port"=>nil, "query"=>nil, "fragment"=>nil, "adapter"=>"sqlite3", "path"=>"db/development.sqlite3"}, @resource_naming_convention=DataMapper::NamingConventions::Resource::UnderscoredAndPluralized, @field_naming_convention=DataMapper::NamingConventions::Field::Underscored, @normalized_uri=sqlite3:db/development.sqlite3?scheme=sqlite&user=&password=&host=&port=&query=&fragment=&adapter=sqlite3&path=db/development.sqlite3>

, - - ( nil ?).

close_connection() DataMapper::Adapters::DataObjectsAdapter, , , .

, !

0

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


All Articles