Package: dj-pgnosql
PG NoSQLUsing Postgres as a NoSQL database. Intended for providing a shared storage space between different django projectsInstallationpip install dj-pgnosqlNote: this package doesn't specify any requirements, but assumes that your project is setup to use Postgres with a version of Django that supportsJSONFieldAddpgnosqltoINSTALLED_APPSin settings.pyRecommended usage (with a custom database)We recommend that you configure pgnosql to use a different database from your project's default database.The idea is that you might have multiple django projects which connect to this KV store as a means to easily share data between servicesConfigure a seperate database connection:settings.pyDATABASES={'default':{'ENGINE':'django.db.backends.postgresql_psycopg2','NAME':os.environ.get('DATABASE_NAME','postgres'),'USER':os.environ.get('DATABASE_USER','postgres'),'HOST':os.environ.get('DATABASE_HOST','postgres'),'PORT':5432,},'pgnosql':{# <- this is our nosql db'ENGINE':'django.db.backends.postgresql_psycopg2','NAME':os.environ.get('NOSQL_DATABASE_NAME','postgres'),'USER':os.environ.get('NOSQL_DATABASE_USER','postgres'),'HOST':os.environ.get('DATABASE_HOST','postgres'),'PORT':5432,}}Add the DB routerDATABASE_ROUTERS=['pgnosql.routers.NoSQLRouter']This router will send queries to the NoSQL database if the model is from thepgnosqlapp. Otherwise will send it to the default databaseRun migrations:You'll need to specify that you're running them for thepgnosqldatabase.webpythonmanage.pymigratepgnosql--database=pgnosqlYou're all setup.Usagefrompgnosql.modelsimportKVkey="foo"value={"bar":"bus"}KV.set(key,value)# value must be jsonKV.get(key)# {"bar": "bus"}KV.delete()You can obviously also just use Django's standard ORMModel fields:key=models.CharField(max_length=100,db_index=True)value=JSONField(default=dict)index=models.CharField(max_length=255,db_index=True,help_text='You can provide an index to make this key searchable')time_to_live=models.PositiveIntegerField(default=0)created_date=models.DateTimeField(auto_now_add=True)modified_date=models.DateTimeField(auto_now=True)Sub-modulesdj=pgnosqlsupplies a few sub-modules for dealing with Specific use-casesGlobalUserA shared user object# Get a userfrompgnosql.userimportGlobalUseruser_id=1user=GlobalUser(user_id)# set arbitary data on a user:user_data={"foo":"bar"}user.set(user_data)user.get()>>{"foo":"bar"}FeedTBDMetricsTBDNotes on versioning:x.y.z
| | |__ Patch
| |____ Minor
|______ MajorPatch: tweaks, improvements and bug fixes - backward compatible. Inclides new functionality in the API interface - but not changes to to itMinor: Changes to the existing API interfaceMajor: Changes to db schema/Django modelsDevelopmentTestingWith docker (recommended)docker-compose run --rm web python manage.py testGenerate Spec Docs:docker-compose run --rm web python manage.py test --testrunner=testreporter.runner.BDDTestRunnerSeespec.txtFAQWhy not use something like Redis or Mongo?Our main motivation for building this library is due to the strong support for Postgres in Django. In most cases - if you're already using Django - you'll be able to use this library with no extra dependencies.You also get all of Django's built in support for Postgress including:Easy to testConfiguration baked inYou're probably already using Postgres for your normal models. Now you don't need to add another piece of machineryDjango Admin supportDjango ORM support...