Skip to content

Commit

Permalink
Implement connect() for SQLite3 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Sep 10, 2017
1 parent 2481b47 commit 468fae8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
13 changes: 12 additions & 1 deletion sqlian/databases.py
Expand Up @@ -47,7 +47,18 @@ def register(scheme, klass, replaces_existing=False):
six.moves.urllib.parse.uses_netloc.append(scheme)


register('sqlite', 'sqlian.sqlite.databases.Database')
# TODO: These don't actually work yet.

# register('mysql', 'sqlian.mysql.MySQLDBDatabase')
# register('mysqldb+mysql', 'sqlian.mysql.MySQLDBDatabase')
# register('pymysql+mysql', 'sqlian.mysql.PyMySQLDatabase')

# register('postgresql', 'sqlian.postgresql.Psycopg2Database')
# register('psycopg2+postgresql', 'sqlian.postgresql.Psycopg2Database')
# register('py-postgresql+postgresql','sqlian.postgresql.PyPostgreSQLDatabase')

register('sqlite', 'sqlian.sqlite.SQLite3Database')
register('sqlite3+sqlite', 'sqlian.sqlite.SQLite3Database')


IN_MEMORY_DB_PATTERN = re.compile(r'^(?P<scheme>\w+)://:memory:$')
Expand Down
4 changes: 4 additions & 0 deletions sqlian/sqlite/databases.py
Expand Up @@ -4,5 +4,9 @@


class SQLite3Database(Database):

dbapi2_module_name = 'sqlite3'
engine_class = Engine

def connect(self, dbapi, database, **kwargs):
return dbapi.connect(database)
17 changes: 16 additions & 1 deletion tests/database/test_sqlite3.py
@@ -1,6 +1,6 @@
import pytest

from sqlian import star
from sqlian import connect, star
from sqlian.sqlite import SQLite3Database


Expand Down Expand Up @@ -47,3 +47,18 @@ def test_insert(db):
assert not rows
names = [r.name for r in db.select('name', from_='person')]
assert names == ['Mosky', 'Keith']


@pytest.mark.parametrize('scheme', ['sqlite', 'sqlite3+sqlite'])
def test_connect(tmpdir, scheme):
dbpath = tmpdir.join('sqlian-connect-test.sqlite3')
db = connect('{scheme}:///{path}'.format(scheme=scheme, path=dbpath))
assert db.is_open()

cursor = db.cursor()
cursor.execute('''CREATE TABLE "person" ("name" TEXT)''')
cursor.execute('''INSERT INTO "person" VALUES ('Mosky')''')
cursor.close()

record, = db.select(star, from_='person')
assert record.name == 'Mosky'

0 comments on commit 468fae8

Please sign in to comment.