Skip to content

Commit

Permalink
utility db function for statement sql table
Browse files Browse the repository at this point in the history
  • Loading branch information
pudo committed Jul 20, 2023
1 parent 2528ac5 commit b1b2ec4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion nomenklatura/statement/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from nomenklatura.statement.statement import Statement, StatementDict
from nomenklatura.statement.serialize import CSV, JSON, FORMATS
from nomenklatura.statement.serialize import CSV, JSON, PACK, FORMATS
from nomenklatura.statement.serialize import write_statements
from nomenklatura.statement.serialize import read_statements, read_path_statements
from nomenklatura.statement.db import make_statement_table

__all__ = [
"Statement",
"StatementDict",
"CSV",
"JSON",
"PACK",
"FORMATS",
"write_statements",
"read_statements",
"make_statement_table",
"read_path_statements",
]
25 changes: 25 additions & 0 deletions nomenklatura/statement/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from sqlalchemy import MetaData, Table, Column, DateTime, Unicode, Boolean

KEY_LEN = 255
VALUE_LEN = 65535


def make_statement_table(metadata: MetaData, name: str = "statement") -> Table:
return Table(
name,
metadata,
Column("id", Unicode(KEY_LEN), primary_key=True, unique=True),
Column("entity_id", Unicode(KEY_LEN), index=True, nullable=False),
Column("canonical_id", Unicode(KEY_LEN), index=True, nullable=True),
Column("prop", Unicode(KEY_LEN), nullable=False),
Column("prop_type", Unicode(KEY_LEN), nullable=False),
Column("schema", Unicode(KEY_LEN), nullable=False),
Column("value", Unicode(VALUE_LEN), nullable=False),
Column("original_value", Unicode(VALUE_LEN), nullable=True),
Column("dataset", Unicode(KEY_LEN), index=True),
Column("lang", Unicode(KEY_LEN), nullable=True),
Column("target", Boolean, default=False, nullable=False),
Column("external", Boolean, default=False, nullable=False),
Column("first_seen", DateTime, nullable=False),
Column("last_seen", DateTime, index=True),
)

0 comments on commit b1b2ec4

Please sign in to comment.