Interact with a Postgres database.
A table can be created with createTable:
psql createTable table: "books" columns: {
"id": "serial primary key",
"title": "varchar(100)"
}
psql insert table: "books" values: {"title": "Ulysses"}
# result: {"id": 1, "title": "Ulysses"}
psql insert table: "books" values: [{"title": "Moby Dick"}, {"title": "War and Peace"}]
# result: [{"id": 2, "title": "Ulysses"}, {"id": 3, "title": "War and Peace"}]
$and and $or can be used to combine queries$lt, $lte, $gt, $gte and $eq can be used as comparison operatorscolumns can be used to filter the selected fieldspsql select table: "books" where: {"title": "Moby Dick"}
# result: [{"id": 2, "title": "Moby Dick"}]
psql select table: "books" where: {"$or": {title: "Moby Dick", "id": {"$lt": 2}}}
# result: [{"id": 1, "title": "Ulysses"}, {"id": 2, "title": "Moby Dick"}]
psql select table: "books" columns: ["title"] where: {"title": "Moby Dick"}
# result: [{"title": "Moby Dick"}]
psql update table: "books" values: {"title": "UPDATED"} where: {"id": {"$gt": 2}}
# result: [{"id": 3, "title": "UPDATED"}]
The where query is optional, but without it all columns will be updated:
psql update table: "books" values: {"title": "UPDATED"}
# result: [
# {"id": 1, "title": "Ulysses"},
# {"id": 2, "title": "Ulysses"},
# {"id": 3, "title": "War and Peace"}
# ]
delete uses a where select query and will return the deleted columns:
psql delete table: "books" where: {"title": "Moby Dick"}
# result: [{"id": 2, "title": "Moby Dick"}]
The where query is optional, but without it all rows will be deleted.
An entire table can be dropped with dropTable:
psql dropTable table: "books"
# Storyscript
result = psql exec query: "select * from my_table where name=%(username)s" data: {"username": "jill"}
# result is an array, with records as JSON objects inside it.
Curious to learn more?
✨🍰✨
oms run createTable -a table=<TABLE_NAME> -a columns=<COLUMNS_DATA> -e POSTGRES_DSN=<POSTGRES_DSN>
oms run dropTable -a table=<TABLE_NAME> -e POSTGRES_DSN=<POSTGRES_DSN>
oms run insert -a table=<TABLE_NAME> -a values=<MAP/LIST_OF_MAP_VALUES> -e POSTGRES_DSN=<POSTGRES_DSN>
oms run select -a table=<TABLE_NAME> -a where=<WHERE_CONDITION> -e POSTGRES_DSN=<POSTGRES_DSN>
oms run update -a table=<TABLE_NAME> -a values=<MAP/LIST_OF_MAP_VALUES> -a where=<WHERE_CONDITION> -e POSTGRES_DSN=<POSTGRES_DSN>
oms run delete -a table=<TABLE_NAME> -a where=<WHERE_CONDITION> -e POSTGRES_DSN=<POSTGRES_DSN>
oms run exec -a query=<QUERY> -a data=<DATA_FOR_QUERY_FIELDS> -e POSTGRES_DSN=<POSTGRES_DSN>
Content type
Image
Digest
Size
41.8 MB
Last updated
almost 7 years ago
docker pull microservices/psql