Skip to content

Latest commit

 

History

History
83 lines (55 loc) · 1.75 KB

database.md

File metadata and controls

83 lines (55 loc) · 1.75 KB

Database

Backing up data

You can easily backup data with

./run.sh backup backups/your_backup_name_here

then load from an existing snapshot with

./run.sh reload_from_backup backups/your_backup_name_here

or from production container mode

./run.sh reload_from_backup -p backups/your_backup_name_here

See run.md for more info.

Using with Python API Server

Access

To access the database, first import the Database class from db.py:

from ..db import Database

Then, you can execute SQL queries by

with Database() as db:
	db.execute("""<SQL HERE>""")	

or if you want the values returned from the execute, use

with Database() as db:
	out = db.execute_return("""<SQL HERE>""")	

which will return a list of the results too.

Note

with Database() as db opens up the db connection, then closes it when the scope is finished

Handling Query Errors from Python Backend

Wrap execute or execute_return in try except statements like this:

with Database() as db:
	try:
		out = db.execute_return("""<SQL HERE>""")	
	except Exception as e:
		# here if you encounter an error in the above query
		pass

to catch errors.

PostgreSQL Shell

To use the shell to run SQL commands to directly on the database, run

sh run.sh psql

which will open up the venome-posgres docker image and login to psql (posgresSQL) for you.

You should get access to the psql shell now, where you can run stuff like

Screenshot 2023-11-11 at 4 17 16 PM

If you have errors, make sure the docker container is already running (./run.sh start cmd).