Expand the `connect` function of `SpatiaLiteDatabase` to accept keyword arguments
To allow for storing numpy.array
types, SQLite needs to be initialized during the connect
statement with the keyword parameter detect_types=sqlite3.PARSE_DECLTYPES
. See the example code:
import sqlite3
import numpy as np
import io
def adapt_array(arr):
out = io.BytesIO()
np.save(out, arr)
return sqlite3.Binary(out.getvalue())
sqlite3.register_adapter(np.ndarray, adapt_array)
sqlite3.register_converter("array", lambda x: np.load(io.BytesIO(x)))
x = np.random.rand(100, 100)
con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)
con.execute("create table test (arr array)")
con.execute("insert into test (arr) values (?)", (x, ))
for r in con.execute("select arr from test"):
print(r[0])
To be able to use SpatiaLiteDatabase
when defining such a data type, the connect
function should be defined as:
def connect(self, init_spatial_metadata=True, **kwargs):
and pass the keyword arguments to the connect
function of sqlite3
.