Skip to main content

Replit DB with a memcache

Project description

Better Replit DB (Python)

Adds a memcache to the standard replit database

To perform database operations such as reading, writing and deleting data, the official replit package simply sends the corresponding request to your REPL's database URL. However, this can be made more efficient by caching the database in RAM using a python dictionary, initialized when the database is created/when the REPL starts. For AsyncDatabase, read operations read from the cache and update/delete operations will update the cache, then perform the action asynchronously as before. The same occurs for the synchronous Database but with regular/synchronous update operations.

Usage

Async:

Replace

from replit.database import AsyncDatabase

async_db = AsyncDatabase(replit_db_url)

with

from betterreplitdb import AsyncDatabase

async_db = AsyncDatabase(replit_db_url)
async_db.init_cache()

Note: Replit's docs say that you need to use AsyncDatabase() to construct a DB. This is false, please use AsyncDatabase(environ["REPLIT_DB_URL"]) instead, where environ is os.environ.

Sync:

Replace

from replit import db

with

from betterreplitdb import db

Version Tracking

This repo is up to date with the main repo with commits:

If these are not the latest commits on these files, please open an issue/PR.

Copyright

This repo is forked from Replit's, which is licensed under the ISC license, as is this project.

Copyright disclaimer for replit/replit-py

Copyright 2021 Replit

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

betterreplitdb-0.0.3.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

betterreplitdb-0.0.3-py3-none-any.whl (7.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page