GithubHelp home page GithubHelp logo

Comments (3)

katarinasupe avatar katarinasupe commented on August 28, 2024 1

@BorisTasevski and @g-despot let's discuss this here sometime soon so that Bruno knows what is best to do next 😄

from gqlalchemy.

brunos252 avatar brunos252 commented on August 28, 2024

Ideas:

  1. make .node() accept kwargs in form of tuple, for instance prop=(value="var", is_variable=True), which would then put var in properties without the quotes, and if we dont pass a tuple, use the value as is.

  2. next to kwargs such as prop="var" also pass prop_is_variable=True when we need the var to be used as variable, and in to_cypher_properties() inside node(), for every kwargs check if there exists _is_variable which is True.

  3. address this in QueryBuilder 2 and put FOREACH on hold

from gqlalchemy.

Josipmrden avatar Josipmrden commented on August 28, 2024

Maybe to introduce a new class inside the QueryBuilder logic, for example Property
which will be utilized like this: https://pypika.readthedocs.io/en/latest/2_tutorial.html#tables-columns-schemas-and-databases

def to_cypher_value(value: Any, config: NetworkXCypherConfig = None) -> str:
    """Converts value to a valid Cypher type."""
    if config is None:
        config = NetworkXCypherConfig()

    value_type = type(value)

    if value_type == str and value.lower() == "null":
        return value
   **if isinstance(value, Property): return str(value)** -> makes Property would just have an initializer with its value

    if value_type == float and math.isnan(value):
        if config.nan_handler == NanValuesHandle.THROW_EXCEPTION:
            raise NanException("Nan values are not allowed!")

        return "null"

    if value_type in [int, float, bool]:
        return str(value)

    if value_type in [list, set, tuple]:
        return f"[{', '.join(map(to_cypher_value, value))}]"

    if value_type == dict:
        lines = ", ".join(f"{k}: {to_cypher_value(v)}" for k, v in value.items())
        return f"{{{lines}}}"

    if value is None:
        return "null"

    if value.lower() in ["true", "false"]:
        return value

    return f"'{value}'"

Which would eliminate all our needs to have "is_variable" in FOREACH, WHERE, NODE, and other clauses. Not to mention we'll have to change it at all these methods if by some chance a lightbulb hits us with a better implementation

from gqlalchemy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.