-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from nebula-contrib/2-framework-agnostic
2 framework agnostic
- Loading branch information
Showing
11 changed files
with
113 additions
and
36 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
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
Empty file.
Empty file.
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,22 @@ | ||
try: | ||
from django.core.management.base import BaseCommand, CommandError | ||
from nebula_carina.models.migrations import make_migrations, migrate | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Run Nebula Graph migrations' | ||
|
||
def handle(self, *args, **options): | ||
migrations = make_migrations() | ||
if not migrations: | ||
self.stdout.write('No Nebula Graph schema change found') | ||
return | ||
self.stdout.write('The following migration NGQLs will be executed: \n\n%s' % ('\n'.join(migrations))) | ||
if input("Type 'yes' to continue, or 'no' to cancel\n") == 'yes': | ||
migrate(make_migrations()) | ||
self.stdout.write(self.style.SUCCESS('Nebula migration succeeded.')) | ||
else: | ||
self.stdout.write(self.style.NOTICE('Nebula migration cancelled.')) | ||
|
||
except ModuleNotFoundError: | ||
pass |
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
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 |
---|---|---|
@@ -1,24 +1,44 @@ | ||
from typing import Iterable, Type | ||
from nebula_carina.models.abstract import NebulaAdaptor | ||
from typing import Type, Iterable | ||
from nebula_carina.models.abstract import NebulaConvertableProtocol | ||
from nebula_carina.ngql.query.conditions import Condition | ||
from nebula_carina.ngql.query.match import match, OrderBy, Limit | ||
|
||
|
||
class SingleMatchResult(object): | ||
|
||
def __init__(self, result: dict[str, NebulaConvertableProtocol]): | ||
self.__data = result | ||
|
||
def dict(self): | ||
return {k: v.dict() for k, v in self.__data.items()} | ||
|
||
def __getitem__(self, item): | ||
return self.__data[item] | ||
|
||
def __iter__(self): | ||
for key, value in self.__data.items(): | ||
yield key, value | ||
|
||
|
||
class ModelBuilder(object): | ||
@staticmethod | ||
def match( | ||
pattern: str, to_model_dict: dict[str, Type[NebulaAdaptor]], # should be model | ||
pattern: str, to_model_dict: dict[str, Type[NebulaConvertableProtocol]], | ||
*, distinct_field: str = None, | ||
condition: Condition = None, order_by: OrderBy = None, limit: Limit = None | ||
) -> Iterable[dict[str, NebulaAdaptor]]: # should be model | ||
) -> Iterable[SingleMatchResult]: # should be model | ||
output = ', '.join( | ||
("DISTINCT " if key == distinct_field else "") + key | ||
for key in to_model_dict.keys() | ||
) | ||
results = match(pattern, output, condition, order_by, limit) | ||
return ( | ||
{ | ||
SingleMatchResult({ | ||
key: to_model_dict[key].from_nebula_db_cls(value.value) | ||
for key, value in zip(results.keys(), row.values) if key in to_model_dict | ||
} for row in results.rows() | ||
}) for row in results.rows() | ||
) | ||
|
||
@staticmethod | ||
def serialized_match(*args, **kwargs): | ||
return [res.dict() for res in ModelBuilder.match(*args, **kwargs)] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
setup( | ||
name='nebula-carina', | ||
version='0.2.1', | ||
version='0.3.0', | ||
author='Sword Elucidator', | ||
author_email='[email protected]', | ||
url='https://github.com/SwordElucidator/nebula-carina', | ||
|