Class: Turso::Connection
- Inherits:
-
Object
- Object
- Turso::Connection
- Defined in:
- lib/turso/connection.rb
Instance Method Summary collapse
- #busy_timeout=(ms) ⇒ Object
- #changes ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #execute(sql, *bind_args) ⇒ Object
- #execute_batch(sql) ⇒ Object
- #get_first_row(sql, *bind_args) ⇒ Object
- #get_first_value(sql, *bind_args) ⇒ Object
-
#initialize(native_connection) ⇒ Connection
constructor
A new instance of Connection.
- #interrupt ⇒ Object
- #last_insert_rowid ⇒ Object
- #prepare(sql) ⇒ Object
- #query(sql, *bind_args) ⇒ Object
- #query_timeout ⇒ Object
- #query_timeout=(ms) ⇒ Object
- #release_savepoint(name) ⇒ Object
- #rollback_to_savepoint(name) ⇒ Object
- #savepoint(name) ⇒ Object
- #total_changes ⇒ Object
Constructor Details
#initialize(native_connection) ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 |
# File 'lib/turso/connection.rb', line 5 def initialize(native_connection) @native = native_connection @closed = false @owner = owner_token end |
Instance Method Details
#busy_timeout=(ms) ⇒ Object
62 63 64 65 |
# File 'lib/turso/connection.rb', line 62 def busy_timeout=(ms) check_owner! @native.busy_timeout = ms.to_i end |
#changes ⇒ Object
87 88 89 90 |
# File 'lib/turso/connection.rb', line 87 def changes check_owner! @native.changes end |
#close ⇒ Object
15 16 17 18 19 |
# File 'lib/turso/connection.rb', line 15 def close return if closed? @native.close @closed = true end |
#closed? ⇒ Boolean
11 12 13 |
# File 'lib/turso/connection.rb', line 11 def closed? @closed end |
#execute(sql, *bind_args) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/turso/connection.rb', line 26 def execute(sql, *bind_args) stmt = prepare(sql) begin stmt.bind(*bind_args) unless bind_args.empty? stmt.run ensure stmt.close end end |
#execute_batch(sql) ⇒ Object
36 37 38 39 |
# File 'lib/turso/connection.rb', line 36 def execute_batch(sql) check_owner! @native.execute_batch(sql) end |
#get_first_row(sql, *bind_args) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/turso/connection.rb', line 47 def get_first_row(sql, *bind_args) stmt = prepare(sql) begin stmt.bind(*bind_args) unless bind_args.empty? stmt.get ensure stmt.close end end |
#get_first_value(sql, *bind_args) ⇒ Object
57 58 59 60 |
# File 'lib/turso/connection.rb', line 57 def get_first_value(sql, *bind_args) row = get_first_row(sql, *bind_args) row&.first end |
#interrupt ⇒ Object
77 78 79 80 |
# File 'lib/turso/connection.rb', line 77 def interrupt check_owner! @native.interrupt end |
#last_insert_rowid ⇒ Object
92 93 94 95 |
# File 'lib/turso/connection.rb', line 92 def last_insert_rowid check_owner! @native.last_insert_rowid end |
#prepare(sql) ⇒ Object
21 22 23 24 |
# File 'lib/turso/connection.rb', line 21 def prepare(sql) check_owner! Statement.new(@native.prepare(sql), self) end |
#query(sql, *bind_args) ⇒ Object
41 42 43 44 45 |
# File 'lib/turso/connection.rb', line 41 def query(sql, *bind_args) stmt = prepare(sql) stmt.bind(*bind_args) unless bind_args.empty? ResultSet.new(stmt) end |
#query_timeout ⇒ Object
72 73 74 75 |
# File 'lib/turso/connection.rb', line 72 def query_timeout check_owner! @native.query_timeout end |
#query_timeout=(ms) ⇒ Object
67 68 69 70 |
# File 'lib/turso/connection.rb', line 67 def query_timeout=(ms) check_owner! @native.query_timeout = ms.to_i end |
#release_savepoint(name) ⇒ Object
101 102 103 |
# File 'lib/turso/connection.rb', line 101 def release_savepoint(name) execute("RELEASE SAVEPOINT #{name}") end |
#rollback_to_savepoint(name) ⇒ Object
105 106 107 |
# File 'lib/turso/connection.rb', line 105 def rollback_to_savepoint(name) execute("ROLLBACK TO SAVEPOINT #{name}") end |
#savepoint(name) ⇒ Object
97 98 99 |
# File 'lib/turso/connection.rb', line 97 def savepoint(name) execute("SAVEPOINT #{name}") end |
#total_changes ⇒ Object
82 83 84 85 |
# File 'lib/turso/connection.rb', line 82 def total_changes check_owner! @native.total_changes end |