-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'relational-data-sink' into dec-demo
- Loading branch information
Showing
5 changed files
with
80 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
stix2/datastore/relational_db/database_backends/sqlite_backend.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os | ||
from typing import Any | ||
|
||
from sqlalchemy import TIMESTAMP, LargeBinary, Text | ||
from sqlalchemy import event | ||
|
||
from stix2.base import ( | ||
_DomainObject, _MetaObject, _Observable, _RelationshipObject, | ||
) | ||
from stix2.datastore.relational_db.utils import schema_for | ||
|
||
from .database_backend_base import DatabaseBackend | ||
|
||
|
||
class SQLiteBackend(DatabaseBackend): | ||
default_database_connection_url = f"sqlite:///stix-data-sink.db" | ||
|
||
def __init__(self, database_connection_url=default_database_connection_url, force_recreate=False, **kwargs: Any): | ||
super().__init__(database_connection_url, force_recreate=force_recreate, **kwargs) | ||
|
||
@event.listens_for(self.database_connection, "connect") | ||
def set_sqlite_pragma(dbapi_connection, connection_record): | ||
cursor = dbapi_connection.cursor() | ||
cursor.execute("PRAGMA foreign_keys=ON") | ||
result = cursor.execute("PRAGMA foreign_keys") | ||
for row in result: | ||
print('PRAGMA foreign_keys:', row) | ||
cursor.close() | ||
|
||
# ========================================================================= | ||
# sql type methods (overrides) | ||
|
||
@staticmethod | ||
def determine_sql_type_for_binary_property(): # noqa: F811 | ||
return SQLiteBackend.determine_sql_type_for_string_property() | ||
|
||
@staticmethod | ||
def determine_sql_type_for_hex_property(): # noqa: F811 | ||
# return LargeBinary | ||
return SQLiteBackend.determine_sql_type_for_string_property() | ||
|
||
@staticmethod | ||
def determine_sql_type_for_timestamp_property(): # noqa: F811 | ||
return TIMESTAMP(timezone=True) | ||
|
||
# ========================================================================= | ||
# Other methods | ||
|
||
@staticmethod | ||
def array_allowed(): | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters