Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Last active July 17, 2021 04:18
Show Gist options
  • Save thanakijwanavit/9c9bbdd918b75361dc2ed33a40200f74 to your computer and use it in GitHub Desktop.
Save thanakijwanavit/9c9bbdd918b75361dc2ed33a40200f74 to your computer and use it in GitHub Desktop.
supermodel for pynamodb
schemaUrl = 'https://raw.githubusercontent.com/thanakijwanavit/villaMasterSchema/master/Product.json'
from nicHelper.pynamodb import SchemaAttribute, SuperModel
from typing import Any
class TestModel(SuperModel):
class Meta:
table_name="colab-test-sensitive-column"
region = 'ap-southeast-1'
dax_read_endpoints = ['longtermcluster.vuu7lr.clustercfg.dax.apse1.cache.amazonaws.com:8111']
dax_write_endpoints = ['longtermcluster.vuu7lr.clustercfg.dax.apse1.cache.amazonaws.com:8111']
data = SchemaAttribute(schemaUrl = schemaUrl, null=True)
phoneHash = UnicodeAttribute(hash_key=True)
# Overrides
def pullOutKeys(self)->None:
self.phoneHash = str(self.data.get('phoneHash') or self.data.get('iprcode') or self.data.get('id') )
@beartype
def toDict(self)->dict:
return self.data
@classmethod
@beartype
def fromDict(cls, inputDict:dict)->Any:
return cls(data=inputDict)
@beartype
def update(self,inputDict:dict)->None:
self.data.update(inputDict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment