2015-03-12 21:21:33 +00:00
|
|
|
require "spec"
|
|
|
|
require "../src/sqlite3"
|
|
|
|
|
|
|
|
include SQLite3
|
2016-06-23 20:27:58 +00:00
|
|
|
|
|
|
|
DB_FILENAME = "./test.db"
|
|
|
|
|
|
|
|
def with_db(&block : DB::Database ->)
|
|
|
|
File.delete(DB_FILENAME) rescue nil
|
|
|
|
DB.open "sqlite3:#{DB_FILENAME}", &block
|
|
|
|
ensure
|
|
|
|
File.delete(DB_FILENAME)
|
|
|
|
end
|
|
|
|
|
2017-03-07 19:52:31 +00:00
|
|
|
def with_cnn(&block : DB::Connection ->)
|
|
|
|
File.delete(DB_FILENAME) rescue nil
|
|
|
|
DB.connect "sqlite3:#{DB_FILENAME}", &block
|
|
|
|
ensure
|
|
|
|
File.delete(DB_FILENAME)
|
|
|
|
end
|
|
|
|
|
2019-04-18 18:58:02 +00:00
|
|
|
def with_db(config, &block : DB::Database ->)
|
|
|
|
uri = "sqlite3:#{config}"
|
|
|
|
filename = SQLite3::Connection.filename(URI.parse(uri))
|
|
|
|
File.delete(filename) rescue nil
|
|
|
|
DB.open uri, &block
|
2016-06-23 20:27:58 +00:00
|
|
|
ensure
|
2019-04-18 18:58:02 +00:00
|
|
|
File.delete(filename) if filename
|
2016-06-23 20:27:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def with_mem_db(&block : DB::Database ->)
|
|
|
|
DB.open "sqlite3://%3Amemory%3A", &block
|
|
|
|
end
|