Comments (5)
Given that that last bit of code doesn't actually work, I tried something similar to:
class CustomId(properties.IdProperty, abc.DataType):
def validate(self, val):
if val is not None:
try:
return str(val)
except ValueError as e:
raise exception.ValidationError(
'Not a valid string: {}'.format(val)) from e
def to_db(self, val=None):
return super(CustomId, self).to_db(val=val)
def to_ogm(self, val):
return super(CustomId, self).to_ogm(val)
class Person(goblin.Vertex):
id = goblin.Property(CustomId(data_type=goblin.String), default='abc123')
but I am really just grasping at straws here.
from goblin.
Well, as far as the goblin.Element
interface is concerned, all instantiated Goblin elements already have an id property:
In [1]: from goblin import Vertex
In [2]: class Person(Vertex): pass
In [3]: p = Person()
In [4]: p.id = 1
In [5]: p.id
Out[5]: 1
Goblin currently doesn't support custom id data types. It possibly could in the future. May I ask why you need this functionality? What provider are you working with? Typically they will handle element ids...
from goblin.
That makes sense, thanks for the response.
My use case is that I have objects with a uid
that I was hoping to use as the authoritative vertex/edge identifier to keep things consistent across the platform. The same uid
in my graph db corresponds to other things in different data stores (like Mysql, AWS S3 key, etc), and I was just trying to keep things the same.
As an easy solution, I can create my own custom property uid
and map it to that, but it just wont match my other datastores in terms of the authoritative identifier of the vertex or edge.
I am working with Amazon Neptune which returns a random uuid when you create a vertex or edge, so I was trying to control that. Running a simple create vertex function sets the id of the object to something similar to
>>> leif.id
'acb0d299-68c3-2687-5cf8-3bc9edf99280'
I am not running the latest goblin due to Neptune's limitations if that makes a difference.
Here are my relevant pip packages:
aiogremlin==3.2.4
goblin==2.0.0
gremlinpython==3.3.1
from goblin.
What if you simply set the id with your own uuid and then save per usual?
leif.id = 'myobjectsuuid'
session.add(leif)
await session.flush()
I ask because I truly don't know...
from goblin.
I thought it would be that easy originally, but it does not seem to be the case.
>>> import goblin
>>> import asyncio
>>> from goblin import Goblin
>>>
>>> class Person(goblin.Vertex):
... car = goblin.VertexProperty(goblin.String)
...
>>> async def store_element(app, vertex1):
... session = await app.session()
... session.add(vertex1)
... await session.flush()
...
>>> loop = asyncio.get_event_loop()
>>> app = loop.run_until_complete(Goblin.open(loop, hosts=["neptune_host"]))
>>> app.register(Person)
>>>
>>> p1 = Person()
>>> p1.id = "abc123"
>>> p1.id
'abc123'
>>>
>>> loop.run_until_complete(store_element(app, p1))
>>> print(p1.id)
0eb0d4ec-f29c-0fc8-d282-f69ad3575497
EDIT: The behavior is the same with or without setting the id
to a goblin.String
property, like shown in the original comment on this ticket.
from goblin.
Related Issues (20)
- Reference instance to test goblin against HOT 3
- How to change version of Goblin OGM Serializer for Janusgraph (TinkerPop 3.2.6) HOT 3
- TypeError: unhashable type: 'dict' when creating an Edge HOT 10
- goblin does not work with aiohttp>=3.0.0 HOT 5
- Question about using a multi-value/set VertexProperty HOT 6
- Vertex property gets changed from Gremlin Console but not from Python/Goblin script HOT 2
- goblin not working with aiohttp (server) HOT 2
- Mocking JanusGraph Connection for unit tests
- Add method to easily remove Vertex HOT 1
- The project appears idle, can I take over? HOT 10
- Problem with Edge data type HOT 5
- App/Cluster configuration using URL HOT 3
- Schema generator HOT 3
- Belated License change HOT 5
- Question: Extent to which OO modeling is supported in Goblin HOT 7
- How to use mixed index in goblin? HOT 4
- AttributeError: AsyncGraphTraversal.last_traverser HOT 1
- [Proposal] - OGM distinct from driver HOT 7
- Unexpected results when updating property HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goblin.