Skip to content

Commit ee45462

Browse files
committed
Support for custom IDs
1 parent ee343f7 commit ee45462

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

indradb/indradb.capnp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@0xc656e2e7cbc5b02e;
22

33
using Timestamp = UInt64;
4-
using Uuid = Data;
4+
using Id = Data;
55
using Type = Text;
66
using Json = Text;
77

@@ -11,13 +11,13 @@ struct Edge {
1111
}
1212

1313
struct EdgeKey {
14-
outboundId @0 :Uuid;
14+
outboundId @0 :Id;
1515
t @1 :Type;
16-
inboundId @2 :Uuid;
16+
inboundId @2 :Id;
1717
}
1818

1919
struct Vertex {
20-
id @0 :Uuid;
20+
id @0 :Id;
2121
t @1 :Type;
2222
}
2323

@@ -26,10 +26,10 @@ struct VertexQuery {
2626
range :group {
2727
limit @0 :UInt32;
2828
t @1 :Type;
29-
startId @2 :Uuid;
29+
startId @2 :Id;
3030
}
3131
specific :group {
32-
ids @3 :List(Uuid);
32+
ids @3 :List(Id);
3333
}
3434
pipe :group {
3535
inner @4 :EdgeQuery;
@@ -77,7 +77,7 @@ struct Property {
7777
}
7878

7979
struct VertexProperty {
80-
id @0 :Uuid;
80+
id @0 :Id;
8181
value @1 :Json;
8282
}
8383

@@ -95,7 +95,7 @@ struct BulkInsertItem {
9595
key @1 :EdgeKey;
9696
}
9797
vertexProperty :group {
98-
id @2 :Uuid;
98+
id @2 :Id;
9999
name @3 :Text;
100100
value @4 :Json;
101101
}
@@ -115,7 +115,7 @@ interface Service {
115115

116116
interface Transaction {
117117
# Creates a new vertex. Returns whether the vertex was successfully
118-
# created - if this is false, it's because a vertex with the same UUID
118+
# created - if this is false, it's because a vertex with the same ID
119119
# already exists.
120120
#
121121
# Arguments
@@ -124,11 +124,11 @@ interface Transaction {
124124

125125
# Creates a new vertex with just a type specification. As opposed to
126126
# `createVertex`, this is used when you do not want to manually specify
127-
# the vertex's UUID. Returns the new vertex's UUID.
127+
# the vertex's ID. Returns the new vertex's ID.
128128
#
129129
# Arguments
130130
# * `t`: The type of the vertex to create.
131-
createVertexFromType @1 (t :Type) -> (result :Uuid);
131+
createVertexFromType @1 (t :Type) -> (result :Id);
132132

133133
# Gets a range of vertices specified by a query.
134134
#
@@ -172,7 +172,7 @@ interface Transaction {
172172
# * `id` - The id of the vertex.
173173
# * `t` - Only get the count for a specified edge type.
174174
# * `direction`: The direction of edges to get.
175-
getEdgeCount @8 (id :Uuid, t :Type, direction :EdgeDirection) -> (result :UInt64);
175+
getEdgeCount @8 (id :Id, t :Type, direction :EdgeDirection) -> (result :UInt64);
176176

177177
# Gets vertex properties.
178178
#

indradb/models.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import uuid
32
import datetime
43

54
from .hook import get_schema
@@ -40,30 +39,30 @@ def __ne__(self, other):
4039
return not self.__eq__(other)
4140

4241
class Vertex(_BaseModel):
43-
"""A vertex, which represents things. Vertices have types and UUIDs."""
42+
"""A vertex, which represents things. Vertices have types and IDs."""
4443

4544
__slots__ = ["id", "t"]
4645

4746
def __init__(self, id, t):
4847
"""
4948
Creates a new vertex.
5049
51-
`id` is the vertex UUID. `t` is the vertex type.
50+
`id` is the vertex ID. `t` is the vertex type.
5251
"""
5352

5453
self.id = id
5554
self.t = t
5655

5756
def to_message(self):
5857
return indradb_capnp.Vertex.new_message(
59-
id=self.id.bytes,
58+
id=self.id,
6059
t=self.t
6160
)
6261

6362
@classmethod
6463
def from_message(cls, message):
6564
return cls(
66-
id=uuid.UUID(bytes=message.id),
65+
id=message.id,
6766
t=message.t
6867
)
6968

@@ -76,8 +75,8 @@ def __init__(self, outbound_id, t, inbound_id):
7675
"""
7776
Creates a new edge key.
7877
79-
`outbound_id` is the vertex UUID from which the edge is outbounding.
80-
`t` is the edge type. `inbound_id` is the vertex UUID into which
78+
`outbound_id` is the vertex ID from which the edge is outbounding.
79+
`t` is the edge type. `inbound_id` is the vertex ID into which
8180
the edge is inbounding.
8281
"""
8382

@@ -87,17 +86,17 @@ def __init__(self, outbound_id, t, inbound_id):
8786

8887
def to_message(self):
8988
return indradb_capnp.EdgeKey.new_message(
90-
outboundId=self.outbound_id.bytes,
89+
outboundId=self.outbound_id,
9190
t=self.t,
92-
inboundId=self.inbound_id.bytes
91+
inboundId=self.inbound_id
9392
)
9493

9594
@classmethod
9695
def from_message(cls, message):
9796
return cls(
98-
outbound_id=uuid.UUID(bytes=message.outboundId),
97+
outbound_id=message.outboundId,
9998
t=message.t,
100-
inbound_id=uuid.UUID(bytes=message.inboundId)
99+
inbound_id=message.inboundId
101100
)
102101

103102
class Edge(_BaseModel):
@@ -153,7 +152,7 @@ def __init__(self, id, value):
153152
@classmethod
154153
def from_message(cls, message):
155154
return cls(
156-
id=uuid.UUID(bytes=message.id),
155+
id=message.id,
157156
value=json.loads(message.value)
158157
)
159158

@@ -221,7 +220,7 @@ def t(self, value):
221220
def to_message(self):
222221
message = indradb_capnp.VertexQuery.new_message()
223222
q = message.init("range")
224-
q.startId = self._start_id.bytes if self._start_id is not None else b""
223+
q.startId = self._start_id if self._start_id is not None else b""
225224
q.limit = self._limit
226225
q.t = self._t or ""
227226
return message
@@ -238,7 +237,7 @@ def to_message(self):
238237
ids = q.init("ids", len(self._ids))
239238

240239
for i, id in enumerate(self._ids):
241-
ids[i] = id.bytes
240+
ids[i] = id
242241

243242
return message
244243

@@ -395,7 +394,7 @@ def __init__(self, id, name, value):
395394
def to_message(self):
396395
message = indradb_capnp.BulkInsertItem.new_message()
397396
container = message.init("vertexProperty")
398-
container.id = self.id.bytes
397+
container.id = self.id
399398
container.name = self.name
400399
container.value = json.dumps(self.value)
401400
return message

indradb/transaction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from .models import Vertex, Edge, VertexProperty, EdgeProperty
2-
import uuid
32
import json
43

54
class Transaction(object):
@@ -22,7 +21,7 @@ def create_vertex_from_type(self, type):
2221
`type` specifies the new vertex's type.
2322
"""
2423

25-
deserialize = lambda message: uuid.UUID(bytes=message.result)
24+
deserialize = lambda message: message.result
2625
return self.trans.createVertexFromType(type).then(deserialize)
2726

2827
def get_vertices(self, query):

0 commit comments

Comments
 (0)