53
53
COUNT , ITEM_COUNT , KEY , UNPROCESSED_ITEMS , STREAM_VIEW_TYPE ,
54
54
STREAM_SPECIFICATION , STREAM_ENABLED , BILLING_MODE , PAY_PER_REQUEST_BILLING_MODE
55
55
)
56
- from pynamodb .util import snake_to_camel_case
57
56
58
57
_T = TypeVar ('_T' , bound = 'Model' )
59
58
_KeyType = Any
@@ -415,11 +414,11 @@ def update(self, actions: Sequence[Action], condition: Optional[Condition] = Non
415
414
if version_condition is not None :
416
415
condition &= version_condition
417
416
kwargs : Dict [str , Any ] = {
418
- snake_to_camel_case ( RETURN_VALUES ): ALL_NEW ,
417
+ 'return_values' : ALL_NEW ,
419
418
}
420
419
421
- if snake_to_camel_case ( RANGE_KEY ) in save_kwargs :
422
- kwargs [snake_to_camel_case ( RANGE_KEY ) ] = save_kwargs [snake_to_camel_case ( RANGE_KEY ) ]
420
+ if 'range_key' in save_kwargs :
421
+ kwargs ['range_key' ] = save_kwargs ['range_key' ]
423
422
424
423
kwargs .update (condition = condition )
425
424
kwargs .update (actions = actions )
@@ -482,8 +481,8 @@ def get_operation_kwargs_from_instance(
482
481
)
483
482
if not is_update :
484
483
kwargs .update (save_kwargs )
485
- elif snake_to_camel_case ( RANGE_KEY ) in save_kwargs :
486
- kwargs [snake_to_camel_case ( RANGE_KEY ) ] = save_kwargs [snake_to_camel_case ( RANGE_KEY ) ]
484
+ elif 'range_key' in save_kwargs :
485
+ kwargs ['range_key' ] = save_kwargs ['range_key' ]
487
486
return self ._get_connection ().get_operation_kwargs (* args , ** kwargs )
488
487
489
488
@classmethod
@@ -771,32 +770,32 @@ def create_table(
771
770
"""
772
771
if not cls .exists ():
773
772
schema = cls ._get_schema ()
774
- if hasattr (cls .Meta , snake_to_camel_case ( READ_CAPACITY_UNITS ) ):
775
- schema [snake_to_camel_case ( READ_CAPACITY_UNITS ) ] = cls .Meta .read_capacity_units
776
- if hasattr (cls .Meta , snake_to_camel_case ( WRITE_CAPACITY_UNITS ) ):
777
- schema [snake_to_camel_case ( WRITE_CAPACITY_UNITS ) ] = cls .Meta .write_capacity_units
778
- if hasattr (cls .Meta , snake_to_camel_case ( STREAM_VIEW_TYPE ) ):
779
- schema [snake_to_camel_case ( STREAM_SPECIFICATION ) ] = {
780
- snake_to_camel_case ( STREAM_ENABLED ) : True ,
781
- snake_to_camel_case ( STREAM_VIEW_TYPE ) : cls .Meta .stream_view_type
773
+ if hasattr (cls .Meta , 'read_capacity_units' ):
774
+ schema ['read_capacity_units' ] = cls .Meta .read_capacity_units
775
+ if hasattr (cls .Meta , 'write_capacity_units' ):
776
+ schema ['write_capacity_units' ] = cls .Meta .write_capacity_units
777
+ if hasattr (cls .Meta , 'stream_view_type' ):
778
+ schema ['stream_specification' ] = {
779
+ 'stream_enabled' : True ,
780
+ 'stream_view_type' : cls .Meta .stream_view_type
782
781
}
783
- if hasattr (cls .Meta , snake_to_camel_case ( BILLING_MODE ) ):
784
- schema [snake_to_camel_case ( BILLING_MODE ) ] = cls .Meta .billing_mode
782
+ if hasattr (cls .Meta , 'billing_mode' ):
783
+ schema ['billing_mode' ] = cls .Meta .billing_mode
785
784
if read_capacity_units is not None :
786
- schema [snake_to_camel_case ( READ_CAPACITY_UNITS ) ] = read_capacity_units
785
+ schema ['read_capacity_units' ] = read_capacity_units
787
786
if write_capacity_units is not None :
788
- schema [snake_to_camel_case ( WRITE_CAPACITY_UNITS ) ] = write_capacity_units
787
+ schema ['write_capacity_units' ] = write_capacity_units
789
788
if billing_mode is not None :
790
- schema [snake_to_camel_case ( BILLING_MODE ) ] = billing_mode
789
+ schema ['billing_mode' ] = billing_mode
791
790
index_data = cls ._get_indexes ()
792
- schema [snake_to_camel_case ( GLOBAL_SECONDARY_INDEXES ) ] = index_data .get (snake_to_camel_case ( GLOBAL_SECONDARY_INDEXES ) )
793
- schema [snake_to_camel_case ( LOCAL_SECONDARY_INDEXES ) ] = index_data .get (snake_to_camel_case ( LOCAL_SECONDARY_INDEXES ) )
794
- index_attrs = index_data .get (snake_to_camel_case ( ATTR_DEFINITIONS ) )
795
- attr_keys = [attr .get (snake_to_camel_case ( ATTR_NAME )) for attr in schema .get (snake_to_camel_case ( ATTR_DEFINITIONS ) )]
791
+ schema ['global_secondary_indexes' ] = index_data .get ('global_secondary_indexes' )
792
+ schema ['local_secondary_indexes' ] = index_data .get ('local_secondary_indexes' )
793
+ index_attrs = index_data .get ('attribute_definitions' )
794
+ attr_keys = [attr .get ('attribute_name' ) for attr in schema .get ('attribute_definitions' )]
796
795
for attr in index_attrs :
797
- attr_name = attr .get (snake_to_camel_case ( ATTR_NAME ) )
796
+ attr_name = attr .get ('attribute_name' )
798
797
if attr_name not in attr_keys :
799
- schema [snake_to_camel_case ( ATTR_DEFINITIONS ) ].append (attr )
798
+ schema ['attribute_definitions' ].append (attr )
800
799
attr_keys .append (attr_name )
801
800
cls ._get_connection ().create_table (
802
801
** schema
@@ -841,24 +840,24 @@ def _get_schema(cls):
841
840
Returns the schema for this table
842
841
"""
843
842
schema : Dict [str , List ] = {
844
- snake_to_camel_case ( ATTR_DEFINITIONS ) : [],
845
- snake_to_camel_case ( KEY_SCHEMA ) : []
843
+ 'attribute_definitions' : [],
844
+ 'key_schema' : []
846
845
}
847
846
for attr_name , attr_cls in cls .get_attributes ().items ():
848
847
if attr_cls .is_hash_key or attr_cls .is_range_key :
849
- schema [snake_to_camel_case ( ATTR_DEFINITIONS ) ].append ({
850
- snake_to_camel_case ( ATTR_NAME ) : attr_cls .attr_name ,
851
- snake_to_camel_case ( ATTR_TYPE ) : attr_cls .attr_type
848
+ schema ['attribute_definitions' ].append ({
849
+ 'attribute_name' : attr_cls .attr_name ,
850
+ 'attribute_type' : attr_cls .attr_type
852
851
})
853
852
if attr_cls .is_hash_key :
854
- schema [snake_to_camel_case ( KEY_SCHEMA ) ].append ({
855
- snake_to_camel_case ( KEY_TYPE ) : HASH ,
856
- snake_to_camel_case ( ATTR_NAME ) : attr_cls .attr_name
853
+ schema ['key_schema' ].append ({
854
+ 'key_type' : HASH ,
855
+ 'attribute_name' : attr_cls .attr_name
857
856
})
858
857
elif attr_cls .is_range_key :
859
- schema [snake_to_camel_case ( KEY_SCHEMA ) ].append ({
860
- snake_to_camel_case ( KEY_TYPE ) : RANGE ,
861
- snake_to_camel_case ( ATTR_NAME ) : attr_cls .attr_name
858
+ schema ['key_schema' ].append ({
859
+ 'key_type' : RANGE ,
860
+ 'attribute_name' : attr_cls .attr_name
862
861
})
863
862
return schema
864
863
@@ -869,35 +868,35 @@ def _get_indexes(cls):
869
868
"""
870
869
if cls ._indexes is None :
871
870
cls ._indexes = {
872
- snake_to_camel_case ( GLOBAL_SECONDARY_INDEXES ) : [],
873
- snake_to_camel_case ( LOCAL_SECONDARY_INDEXES ) : [],
874
- snake_to_camel_case ( ATTR_DEFINITIONS ) : []
871
+ 'global_secondary_indexes' : [],
872
+ 'local_secondary_indexes' : [],
873
+ 'attribute_definitions' : []
875
874
}
876
875
cls ._index_classes = {}
877
876
for name , index in getmembers (cls , lambda o : isinstance (o , Index )):
878
877
cls ._index_classes [index .Meta .index_name ] = index
879
878
schema = index ._get_schema ()
880
879
idx = {
881
- snake_to_camel_case ( INDEX_NAME ) : index .Meta .index_name ,
882
- snake_to_camel_case ( KEY_SCHEMA ) : schema .get (snake_to_camel_case ( KEY_SCHEMA ) ),
883
- snake_to_camel_case ( PROJECTION ) : {
880
+ 'index_name' : index .Meta .index_name ,
881
+ 'key_schema' : schema .get ('key_schema' ),
882
+ 'projection' : {
884
883
PROJECTION_TYPE : index .Meta .projection .projection_type ,
885
884
},
886
885
887
886
}
888
887
if isinstance (index , GlobalSecondaryIndex ):
889
888
if getattr (cls .Meta , 'billing_mode' , None ) != PAY_PER_REQUEST_BILLING_MODE :
890
- idx [snake_to_camel_case ( PROVISIONED_THROUGHPUT ) ] = {
889
+ idx ['provisioned_throughput' ] = {
891
890
READ_CAPACITY_UNITS : index .Meta .read_capacity_units ,
892
891
WRITE_CAPACITY_UNITS : index .Meta .write_capacity_units
893
892
}
894
- cls ._indexes [snake_to_camel_case ( ATTR_DEFINITIONS ) ].extend (schema .get (snake_to_camel_case ( ATTR_DEFINITIONS ) ))
893
+ cls ._indexes ['attribute_definitions' ].extend (schema .get ('attribute_definitions' ))
895
894
if index .Meta .projection .non_key_attributes :
896
- idx [snake_to_camel_case ( PROJECTION ) ][NON_KEY_ATTRIBUTES ] = index .Meta .projection .non_key_attributes
895
+ idx ['projection' ][NON_KEY_ATTRIBUTES ] = index .Meta .projection .non_key_attributes
897
896
if isinstance (index , GlobalSecondaryIndex ):
898
- cls ._indexes [snake_to_camel_case ( GLOBAL_SECONDARY_INDEXES ) ].append (idx )
897
+ cls ._indexes ['global_secondary_indexes' ].append (idx )
899
898
else :
900
- cls ._indexes [snake_to_camel_case ( LOCAL_SECONDARY_INDEXES ) ].append (idx )
899
+ cls ._indexes ['local_secondary_indexes' ].append (idx )
901
900
return cls ._indexes
902
901
903
902
def _get_save_args (self , attributes = True , null_check = True ):
@@ -919,9 +918,9 @@ def _get_save_args(self, attributes=True, null_check=True):
919
918
range_key = attribute_values .pop (range_key_attribute .attr_name , {}).get (range_key_attribute .attr_type )
920
919
args = (hash_key , )
921
920
if range_key is not None :
922
- kwargs [snake_to_camel_case ( RANGE_KEY ) ] = range_key
921
+ kwargs ['range_key' ] = range_key
923
922
if attributes :
924
- kwargs [snake_to_camel_case ( ATTRIBUTES ) ] = attribute_values
923
+ kwargs ['attributes' ] = attribute_values
925
924
return args , kwargs
926
925
927
926
def _handle_version_attribute (self , serialized_attributes , actions = None ):
@@ -941,16 +940,16 @@ def _handle_version_attribute(self, serialized_attributes, actions=None):
941
940
version_condition = version_attribute == version_attribute_value
942
941
if actions :
943
942
actions .append (version_attribute .add (1 ))
944
- elif snake_to_camel_case ( ATTRIBUTES ) in serialized_attributes :
945
- serialized_attributes [snake_to_camel_case ( ATTRIBUTES ) ][version_attribute .attr_name ] = self ._serialize_value (
943
+ elif 'attributes' in serialized_attributes :
944
+ serialized_attributes ['attributes' ][version_attribute .attr_name ] = self ._serialize_value (
946
945
version_attribute , version_attribute_value + 1
947
946
)
948
947
else :
949
948
version_condition = version_attribute .does_not_exist ()
950
949
if actions :
951
950
actions .append (version_attribute .set (1 ))
952
- elif snake_to_camel_case ( ATTRIBUTES ) in serialized_attributes :
953
- serialized_attributes [snake_to_camel_case ( ATTRIBUTES ) ][version_attribute .attr_name ] = self ._serialize_value (
951
+ elif 'attributes' in serialized_attributes :
952
+ serialized_attributes ['attributes' ][version_attribute .attr_name ] = self ._serialize_value (
954
953
version_attribute , 1
955
954
)
956
955
0 commit comments