Skip to content

Commit 5319228

Browse files
committed
WL11448: New document _id generation support
The MySQL Connector/Python X DevAPI provides functionality to create the id field (_id) in the documents when the user does not provide one. However, with the introduction of WL#11390 this capability will be available at the server side. In addition connectors shall not create ids anymore to avoid possible collisions. Generated ids at the server side will be available on the result of the execution of the add statement through the method get_generated_ids(), which returns a list. v6
1 parent c83b169 commit 5319228

21 files changed

+345
-201
lines changed

lib/mysqlx/crud.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -400,7 +400,6 @@ def add_or_replace_one(self, doc_id, doc):
400400
"""
401401
if not isinstance(doc, DbDoc):
402402
doc = DbDoc(doc)
403-
doc.ensure_id(doc_id)
404403
return self.add(doc).upsert(True).execute()
405404

406405
def get_one(self, doc_id):

lib/mysqlx/dbdoc.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -29,7 +29,6 @@
2929
"""Implementation of the DbDoc."""
3030

3131
import json
32-
import uuid
3332

3433
from .compat import STRING_TYPES
3534
from .errors import ProgrammingError
@@ -70,17 +69,3 @@ def keys(self):
7069
`list`: The keys.
7170
"""
7271
return self.__dict__.keys()
73-
74-
def ensure_id(self, doc_id=None):
75-
"""Ensure ID.
76-
77-
Args:
78-
doc_id (str): Document ID.
79-
"""
80-
if doc_id:
81-
self.__dict__["_id"] = doc_id
82-
elif "_id" not in self.__dict__:
83-
uuid1 = str(uuid.uuid1()).upper().split("-")
84-
uuid1.reverse()
85-
self.__dict__["_id"] = "".join(uuid1)
86-
return self.__dict__["_id"]

lib/mysqlx/protobuf/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -59,6 +59,7 @@
5959
"Mysqlx.Resultset.FetchDoneMoreOutParams"),
6060
)
6161

62+
PROTOBUF_REPEATED_TYPES = [list]
6263

6364
try:
6465
import _mysqlxpb
@@ -71,6 +72,14 @@
7172
from google.protobuf import descriptor_pb2
7273
from google.protobuf import descriptor_pool
7374
from google.protobuf import message_factory
75+
from google.protobuf.internal.containers import (
76+
RepeatedCompositeFieldContainer)
77+
try:
78+
from google.protobuf.pyext._message import (
79+
RepeatedCompositeContainer)
80+
PROTOBUF_REPEATED_TYPES.append(RepeatedCompositeContainer)
81+
except ImportError:
82+
pass
7483

7584
from . import mysqlx_connection_pb2
7685
from . import mysqlx_crud_pb2
@@ -85,6 +94,8 @@
8594

8695
HAVE_MYSQLXPB_CEXT = False
8796

97+
PROTOBUF_REPEATED_TYPES.append(RepeatedCompositeFieldContainer)
98+
8899
# Dictionary with all messages descriptors
89100
_MESSAGES = {}
90101

lib/mysqlx/protobuf/mysqlx_crud_pb2.py

Lines changed: 58 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)