mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Add drop table syntax
* Allows to run all test in same database by deleting tables if exists
This commit is contained in:
parent
07b4e9f4a8
commit
074368a47e
1 changed files with 9 additions and 0 deletions
|
@ -72,6 +72,7 @@ module DB
|
|||
db_spec_config select_1column_syntax : Proc(String, ColumnDef, String), block: true
|
||||
db_spec_config select_2columns_syntax : Proc(String, ColumnDef, ColumnDef, String), block: true
|
||||
db_spec_config select_count_syntax : Proc(String, String), block: true
|
||||
db_spec_config drop_table_if_exists_syntax : Proc(String, String), block: true
|
||||
|
||||
record SpecIt, description : String, prepared : Symbol, file : String, line : Int32, end_line : Int32, block : DB::Database -> Nil
|
||||
getter its = [] of SpecIt
|
||||
|
@ -266,6 +267,9 @@ module DB
|
|||
def with_db(options = nil)
|
||||
@before.call
|
||||
DB.open("#{connection_string}#{"?#{options}" if options}") do |db|
|
||||
db.exec(sql_drop_table("table1"))
|
||||
db.exec(sql_drop_table("table2"))
|
||||
db.exec(sql_drop_table("person"))
|
||||
yield db
|
||||
end
|
||||
ensure
|
||||
|
@ -380,6 +384,11 @@ module DB
|
|||
select_1column_syntax.call("table2", col)
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
def sql_drop_table(table_name)
|
||||
drop_table_if_exists_syntax.call(table_name)
|
||||
end
|
||||
|
||||
def self.run(description = "as a db")
|
||||
ctx = self.new
|
||||
with ctx yield
|
||||
|
|
Loading…
Reference in a new issue