Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Postgresql compatability (#17)
Browse files Browse the repository at this point in the history
* Node ids should be big ints

Use sqlalchemy BigInteger datatype for 64-bit ints

* Only include the foreign keys PRAGMA if using sqlite

Use the connect_record to test the dialect being used
  • Loading branch information
Dan-Staff committed Jan 2, 2019
1 parent 7f5dca3 commit 8ff0dfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions fornax/api.py
Expand Up @@ -20,6 +20,9 @@
# enforce foreign key constrains in SQLite
@event.listens_for(Engine, "connect")
def _set_sqlite_pragma(dbapi_connection, connection_record):
dialect_name = connection_record._ConnectionRecord__pool._dialect.name
if dialect_name != 'sqlite':
return
cursor = dbapi_connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
Expand Down
12 changes: 6 additions & 6 deletions fornax/model.py
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy import ForeignKey, ForeignKeyConstraint
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship

from sqlalchemy.types import BigInteger
Base = declarative_base()


Expand Down Expand Up @@ -51,8 +51,8 @@ class Match(Base):
)
)

start = Column(Integer)
end = Column(Integer)
start = Column(BigInteger)
end = Column(BigInteger)
start_graph_id = Column(Integer)
end_graph_id = Column(Integer)
query_id = Column(Integer)
Expand Down Expand Up @@ -96,7 +96,7 @@ class Node(Base):
PrimaryKeyConstraint('graph_id', 'node_id'),
)
node_id = Column(
Integer,
BigInteger,
CheckConstraint("node_id>=0", name="q_min_id_check")
)
graph_id = Column(Integer, ForeignKey("graph.graph_id"))
Expand Down Expand Up @@ -127,8 +127,8 @@ class Edge(Base):
)
)

start = Column(Integer)
end = Column(Integer)
start = Column(BigInteger)
end = Column(BigInteger)
graph_id = Column(Integer)
meta = Column(String, nullable=True)

Expand Down

0 comments on commit 8ff0dfe

Please sign in to comment.