Giter Site home page Giter Site logo

Comments (7)

robinedwards avatar robinedwards commented on July 26, 2024

unique_index and index already handle the indexing. any property where these are used are automatically indexed. (Using the equivalent of get_or_create_index_node under the hood)

I had considered supporting default values for properties which could either contain a constant or a function to call.

def uid_generator():
return uid
uid = StringProperty(default=uid_generator, unique_index=True)

This could be used to create a custom UnqiueID property, it's probably worth mentioning that it's easy to subclass the current properties.

I will add in the hook necessary for default values this evening

from neomodel.

opqopq avatar opqopq commented on July 26, 2024

Default value is an excellent idea.
Here the point is more to emulate one py2neo function, which is get_or_create indexed node. The point would be that I can do, in my codeclass Place(StructuredNode): name=StringProperty()
Place.get_or_create(name="Home")#first time-> create the nodePlace.get_or_create(nmae='Home')-> node already exist: just send a reference to it

Date: Wed, 31 Oct 2012 08:39:51 -0700
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [neomodel] [Feature Request] Smart Creation (#21)

unique_index and index already handle the indexing. any property where these are used are automatically indexed. (Using the equivalent of get_or_create_index_node under the hood)

I had considered supporting default values for properties which could either contain a constant or a function to call.

def uid_generator():

return uid

uid = StringProperty(default=uid_generator, unique_index=True)

This could be used to create a custom UnqiueID property, it's probably worth mentioning that it's easy to subclass the current properties.

I will add in the hook necessary for default values this evening

          —

          Reply to this email directly or view it on GitHub.

from neomodel.

robinedwards avatar robinedwards commented on July 26, 2024

Hey,

Just pushed support for default values so you can handle uid generation. As it happens we need this feature at work.

What your trying to do with get_or_create is basically the equivalent of:

try:
    p = Person.get(name='tim')
except Person.DoesNotExist:
    p = Person(name='jim')

Which is not too much longer and very easy to read. The issue with get or create is that each item can have multiple properties in an index as opposed to one. Some of those properties are not necessarily unique.

R

from neomodel.

opqopq avatar opqopq commented on July 26, 2024

You're right. Indeed, this try/except should be enough.

Date: Thu, 1 Nov 2012 07:50:35 -0700
From: [email protected]
To: [email protected]
CC: [email protected]
Subject: Re: [neomodel] [Feature Request] Smart Creation (#21)

Hey,

Just pushed support for default values so you can handle uid generation. As it happens we need this feature at work.

What your trying to do with get_or_create is basically the equivalent of:

try:
p = Person.get(name='tim')
except Person.DoesNotExist:
p = Person(name='jim')

Which is not too much longer and very easy to read. The issue with get or create is that each item can have multiple properties in an index as opposed to one. Some of those properties are not necessarily unique.

R

          —

          Reply to this email directly or view it on GitHub.

from neomodel.

opqopq avatar opqopq commented on July 26, 2024

Just on remark though: unless mistaken, the 'get' method you're suggesting is not existing in my version. Is it something being developped ?

from neomodel.

pkatseas avatar pkatseas commented on July 26, 2024

Ah, there's a '.index' missing there. Should be
Person.index.get(name='test')

On Mon, Nov 5, 2012 at 5:39 PM, opqopq [email protected] wrote:

Just on remark though: unless mistaken, the 'get' method you're suggesting
is not existing in my version. Is it something being developped ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/21#issuecomment-10079973.

from neomodel.

opqopq avatar opqopq commented on July 26, 2024

Thanks !

from neomodel.

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.