Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Enum and JSONString type #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

from fastapi import FastAPI

from example.models import VirtualCharacter, Love, Figure, Source, Support, LimitedCharacter
from example.models import (
VirtualCharacter,
Love,
Figure,
Source,
Support,
LimitedCharacter,
)
from nebula_carina.models.migrations import make_migrations, migrate
from nebula_carina.models.model_builder import ModelBuilder
from nebula_carina.models.models import EdgeModel
Expand All @@ -14,8 +21,12 @@

app = FastAPI()


@app.get("/")
async def root():
pass
# rest = make_migrations()
# print(rest)
# run_ngql('SHOW SPACES;')
# print(show_spaces())
# print(use_space('main'))
Expand Down Expand Up @@ -105,27 +116,32 @@ async def root():
# ).save()
# EdgeModel(src_vid='char_test1', dst_vid='char_test2', ranking=0, edge_type=Love(way='gun', times=40)).save()
# return EdgeModel.objects.find_between('char_test1', 'char_test2')
character1 = VirtualCharacter.objects.get('char_test1')
# LocalSession().session.release()
character2 = VirtualCharacter.objects.get('char_test2')
character1.get_out_edges(Love)
character2.get_reverse_edges(Love)
character1.get_out_edge_and_destinations(Love, VirtualCharacter)
character2.get_reverse_edge_and_sources(Love, VirtualCharacter)
VirtualCharacter.objects.find_destinations('char_test1', Love)
VirtualCharacter.objects.find_sources('char_test2', Love, distinct=False, limit=Limit(1))
character2.get_sources(Love, VirtualCharacter)
character1.get_destinations(Love, VirtualCharacter)
# return character1
# return rst
# return ModelBuilder.match(
# '(v)-[e:love]->(v2)', {'v': VirtualCharacter, 'e': EdgeModel, 'v2': VirtualCharacter},
# condition=Q(v__id__in=[112, 113]),
# character1 = VirtualCharacter.objects.get("char_test1")
# # LocalSession().session.release()
# character2 = VirtualCharacter.objects.get("char_test2")
# character1.get_out_edges(Love)
# character2.get_reverse_edges(Love)
# character1.get_out_edge_and_destinations(Love, VirtualCharacter)
# character2.get_reverse_edge_and_sources(Love, VirtualCharacter)
# VirtualCharacter.objects.find_destinations("char_test1", Love)
# VirtualCharacter.objects.find_sources(
# "char_test2", Love, distinct=False, limit=Limit(1)
# )
# character2.get_sources(Love, VirtualCharacter)
# character1.get_destinations(Love, VirtualCharacter)
# # return character1
# # return rst
# # return ModelBuilder.match(
# # '(v)-[e:love]->(v2)', {'v': VirtualCharacter, 'e': EdgeModel, 'v2': VirtualCharacter},
# # condition=Q(v__id__in=[112, 113]),
# # )
# # EdgeModel(src_vid='char_test1', dst_vid='char_test2', ranking=0, edge_type=Love(way='gun', times=40)).save()
# return ModelBuilder.serialized_match(
# "(v)-[e:love]->(v2)",
# {
# "v": VirtualCharacter,
# "e": EdgeModel,
# "v2": VirtualCharacter,
# },
# condition=Q(v__id="char_test1"),
# )
# EdgeModel(src_vid='char_test1', dst_vid='char_test2', ranking=0, edge_type=Love(way='gun', times=40)).save()
return ModelBuilder.serialized_match(
'(v)-[e:love]->(v2)', {
'v': VirtualCharacter, 'e': EdgeModel, 'v2': VirtualCharacter,
},
condition=Q(v__id="char_test1"),
)
13 changes: 0 additions & 13 deletions nebula_carina/apps.py

This file was deleted.

Empty file.
Empty file.
22 changes: 0 additions & 22 deletions nebula_carina/management/commands/nebulamigrate.py

This file was deleted.

8 changes: 4 additions & 4 deletions nebula_carina/models/migrations.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from nebula_carina.models.models import TagModel, EdgeTypeModel
from nebula_carina.ngql.connection.connection import run_ngql
from nebula_carina.ngql.schema.schema import show_tags, show_edges
from nebula_carina.settings import database_settings
from importlib import import_module
import inspect


def make_migrations():
def make_migrations(model_paths: list[str] = None):
existing_tags = show_tags()
existing_edges = show_edges()
ngql_list = []
model_paths = database_settings.model_paths
for model_path in model_paths:
module = import_module(model_path)
for name, cls in module.__dict__.items():
if inspect.isclass(cls) and (issubclass(cls, TagModel) or issubclass(cls, EdgeTypeModel)):
if inspect.isclass(cls) and (
issubclass(cls, TagModel) or issubclass(cls, EdgeTypeModel)
):
if cls.db_name() in existing_tags or cls.db_name() in existing_edges:
alter_schema_ngql = cls.alter_schema_ngql()
alter_schema_ngql and ngql_list.append(alter_schema_ngql)
Expand Down
Loading