mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
update to refactored api
refactor specs
This commit is contained in:
parent
5266a7e7b3
commit
add75d86bf
6 changed files with 131 additions and 73 deletions
23
src/sqlite3/connection.cr
Normal file
23
src/sqlite3/connection.cr
Normal file
|
@ -0,0 +1,23 @@
|
|||
class SQLite3::Connection < DB::Connection
|
||||
def initialize(options)
|
||||
super
|
||||
filename = options["database"]
|
||||
check LibSQLite3.open_v2(filename, out @db, (LibSQLite3::Flag::READWRITE | LibSQLite3::Flag::CREATE), nil)
|
||||
end
|
||||
|
||||
def prepare(query)
|
||||
Statement2.new(self, query)
|
||||
end
|
||||
|
||||
def perform_close
|
||||
LibSQLite3.close_v2(self)
|
||||
end
|
||||
|
||||
def to_unsafe
|
||||
@db
|
||||
end
|
||||
|
||||
private def check(code)
|
||||
raise Exception.new(self) unless code == 0
|
||||
end
|
||||
end
|
|
@ -1,21 +1,6 @@
|
|||
class SQLite3::Driver < DB::Driver
|
||||
def initialize(options)
|
||||
super
|
||||
filename = options["database"]
|
||||
check LibSQLite3.open_v2(filename, out @db, (LibSQLite3::Flag::READWRITE | LibSQLite3::Flag::CREATE), nil)
|
||||
# @closed = false
|
||||
end
|
||||
|
||||
def prepare(query)
|
||||
Statement2.new(self, query)
|
||||
end
|
||||
|
||||
def to_unsafe
|
||||
@db
|
||||
end
|
||||
|
||||
private def check(code)
|
||||
raise Exception.new(@db) unless code == 0
|
||||
def build_connection
|
||||
SQLite3::Connection.new(options)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class SQLite3::ResultSet2 < DB::ResultSet
|
|||
when LibSQLite3::Code::DONE
|
||||
false
|
||||
else
|
||||
raise Exception.new(@statement.driver)
|
||||
raise Exception.new(@statement.connection)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,6 +65,10 @@ class SQLite3::ResultSet2 < DB::ResultSet
|
|||
String.new LibSQLite3.column_name(self, index)
|
||||
end
|
||||
|
||||
def column_type(index : Int32)
|
||||
raise "not implemented"
|
||||
end
|
||||
|
||||
def to_unsafe
|
||||
@statement.to_unsafe
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
class SQLite3::Statement2 < DB::Statement
|
||||
def initialize(@driver, sql)
|
||||
check LibSQLite3.prepare_v2(@driver, sql, sql.bytesize + 1, out @stmt, nil)
|
||||
# @closed = false
|
||||
def initialize(connection, sql)
|
||||
super(connection)
|
||||
check LibSQLite3.prepare_v2(@connection, sql, sql.bytesize + 1, out @stmt, nil)
|
||||
end
|
||||
|
||||
protected def before_execute
|
||||
protected def begin_parameters
|
||||
LibSQLite3.reset(self)
|
||||
end
|
||||
|
||||
|
@ -23,7 +23,7 @@ class SQLite3::Statement2 < DB::Statement
|
|||
bind_arg(index, value)
|
||||
end
|
||||
|
||||
protected def execute
|
||||
protected def perform
|
||||
ResultSet2.new(self)
|
||||
end
|
||||
|
||||
|
@ -56,7 +56,7 @@ class SQLite3::Statement2 < DB::Statement
|
|||
end
|
||||
|
||||
private def check(code)
|
||||
raise Exception.new(@driver) unless code == 0
|
||||
raise Exception.new(@connection) unless code == 0
|
||||
end
|
||||
|
||||
def to_unsafe
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue