11# ------------------------------------------------------------------------------
2- # Copyright (c) 2020, 2023 , Oracle and/or its affiliates.
2+ # Copyright (c) 2020, 2024 , Oracle and/or its affiliates.
33#
44# This software is dual-licensed to you under the Universal Permissive License
55# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -74,7 +74,8 @@ cdef class ThickSodaDbImpl(BaseSodaDbImpl):
7474
7575 def create_document (self , bytes content , str key , str media_type ):
7676 """
77- Internal method for creating a document.
77+ Internal method for creating a document containing binary or encoded
78+ text data.
7879 """
7980 cdef:
8081 StringBuffer media_type_buf = StringBuffer()
@@ -93,6 +94,24 @@ cdef class ThickSodaDbImpl(BaseSodaDbImpl):
9394 _raise_from_odpi()
9495 return doc_impl
9596
97+ def create_json_document (self , object content , str key ):
98+ """
99+ Internal method for creating a document containing JSON.
100+ """
101+ cdef:
102+ StringBuffer key_buf = StringBuffer()
103+ JsonBuffer json_buf = JsonBuffer()
104+ ThickSodaDocImpl doc_impl
105+ key_buf.set_value(key)
106+ json_buf.from_object(content)
107+ doc_impl = ThickSodaDocImpl.__new__ (ThickSodaDocImpl)
108+ if dpiSodaDb_createJsonDocument(self ._handle, key_buf.ptr,
109+ key_buf.length, & json_buf._top_node,
110+ DPI_SODA_FLAGS_DEFAULT,
111+ & doc_impl._handle) < 0 :
112+ _raise_from_odpi()
113+ return doc_impl
114+
96115 def get_collection_names (self , str start_name , uint32_t limit ):
97116 """
98117 Internal method for getting the list of collection names.
@@ -163,7 +182,7 @@ cdef class ThickSodaCollImpl(BaseSodaCollImpl):
163182 Internal method for populating the SODA operations structure with the
164183 information provided by the user.
165184 """
166- if dpiContext_initSodaOperOptions(driver_context , options) < 0 :
185+ if dpiContext_initSodaOperOptions(driver_info.context , options) < 0 :
167186 _raise_from_odpi()
168187 options.hint = ptr
169188 options.hintLength = length
@@ -489,20 +508,29 @@ cdef class ThickSodaDocImpl(BaseSodaDocImpl):
489508 Internal method for returning the content of the document.
490509 """
491510 cdef:
492- bytes out_content = None
511+ object out_content = None
493512 str out_encoding = None
494513 const char * encoding
495514 uint32_t content_len
496515 const char * content
497- if dpiSodaDoc_getContent(self ._handle, & content, & content_len,
498- & encoding) < 0 :
516+ dpiJson * json
517+ bint is_json
518+ if dpiSodaDoc_getIsJson(self ._handle, & is_json) < 0 :
499519 _raise_from_odpi()
500- if content ! = NULL :
501- out_content = content[:content_len]
502- if encoding ! = NULL :
503- out_encoding = encoding.decode( )
520+ if is_json :
521+ if dpiSodaDoc_getJsonContent( self ._handle, & json) < 0 :
522+ _raise_from_odpi()
523+ out_content = _convert_json_to_python(json )
504524 else :
505- out_encoding = " UTF-8"
525+ if dpiSodaDoc_getContent(self ._handle, & content, & content_len,
526+ & encoding) < 0 :
527+ _raise_from_odpi()
528+ if content != NULL :
529+ out_content = content[:content_len]
530+ if encoding != NULL :
531+ out_encoding = encoding.decode()
532+ else :
533+ out_encoding = " UTF-8"
506534 return (out_content, out_encoding)
507535
508536 def get_created_on (self ):
@@ -637,7 +665,7 @@ cdef class ThickSodaOpImpl:
637665 uint32_t i
638666 impl._buffers = []
639667 options = & impl._options
640- if dpiContext_initSodaOperOptions(driver_context , options) < 0 :
668+ if dpiContext_initSodaOperOptions(driver_info.context , options) < 0 :
641669 _raise_from_odpi()
642670 if op._keys:
643671 options.numKeys = < uint32_t> len (op._keys)
0 commit comments