global JSON RPC use TS and global model
1.1K
An optimized Docker container designed for seamless execution of Sequelize, enabling swift and efficient database operations within Node.js environments.
In order to run this container you'll need docker installed.
To run this container, you need to supply your own Node.js package model using Sequelize and specify your package name within the environment variable DB_MODULE.
Here is an example of the model usage with Sequelize and TypeScript:
Pull the image
docker pull potatodeveloper/jsonrpc-dblink:latest
Run the container
docker run \
-e API_KEY=[API_KEY_FOR_AUTH] \
-e DB_USER=[db_user] \
-e DB_PASSWORD=[db_password] \
-e DB_NAME=[db_name] \
-e DB_HOST=[db_bost] \
-e DB_PORT=[db_port] \
-e REDIS_STORE=[redis_host] \
-e REDIS_PORT=[redis_port] \
-e REDIS_PASSWORD=[redis_password] \
-e DB_MODULE=[database_package_module] \
-p [external_port]:3000 \
-d \
potatodeveloper/jsonrpc-dblink:latest
Docker compose example
version: '3'
services:
- redis:
container_name: redis
image: redis:7.0.4-alpine
restart: always
ports:
- ${RD_PORT}:6379
command: redis-server --save 20 1 --loglevel warning --requirepass example_password
volumes:
- ./cache:/data
networks:
- dblink-net
postgres:
container_name: postgres
image: postgres:14.5-alpine
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=example_password
- POSTGRES_DB=jsonrpc
ports:
- ${POSTGRES_PORT}:5432
volumes:
- ./postgres:/var/lib/postgresql/data
networks:
- dblink-net
dblink:
container_name: dblink
image: potatodeveloper/jsonrpc-dblink:latest
ports:
- '3001:3000'
environment:
- DB_USER=postgres
- DB_PASSWORD=example_password
- DB_NAME=jsonrpc
- DB_HOST=postgres
- DB_PORT=5432
- API_KEY=example_key
- REDIS_STORE=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=example_password
- DB_MODULE=model-example-dblink
- DB_EXTENSIONS=uuid-ossp
- GIT_HOST=${GIT_HOST}
- GIT_PORT=${GIT_PORT}
- SSH_PUBLIC=${SSH_PUBLIC}
- SSH_PRIVATE=${SSH_PRIVATE}
depends_on:
- redis
- postgres
networks:
- dblink-net
networks:
dblink-net:
PORT - Custom internal portAPI_KEY - API Key for jsonrpc-dblinkELASTICSEARCH_URL - Elasticsearch URLELASTICSEARCH_USERNAME - Elasticsearch UsernameELASTICSEARCH_PASSWORD - Elasticsearch PasswordREDIS_STORE - Redis hostnameREDIS_PORT - Redis portREDIS_PASSWORD - Redis passwordDB_USER - Database userDB_PASSWORD - Database passwordDB_NAME - Database nameDB_HOST - Database hostDB_PORT - Database portDB_MODULE - Database node package moduleGIT_HOST - Git URL for package from repositoryGIT_PORT - Git port (other than default port 22)SSH_PUBLIC - SSH base64 encrypted id_rsa.pub or id_ed25529.pub for private repositorySSH_PRIVATE SSH base64 encrypted id_rsa or id_ed25529 for private repositoryDB_EXTENSIONS - Database extension (e.g. : uuid-ossp,other-ext,another-ext)COMMAND_HANDLER - enable/disable command handler ,default:true)QUERY_HANDLER - enable/disable query handler ,default:true)COMMAND_METHOD_OVERRIDE - default: "command.[method]"QUERY_METHOD_OVERRIDE - default: "query.[method]"Below is the list of methods that can be utilized. For further details on how to use these queries, please refer to the Sequelize documentation page.
model will be expressed by field idmodel will be expressed by string instead of object{
model: MyModel;
}
{
"model": "MyModel"
}
Op will be expressed by string instead of object{
[Op.in]: [1,2,3,4]
}
{
"Op.in": [1, 2, 3, 4]
}
http://localhost:3001/rpc
// method post only
POST
master-api-key=example_key
curl --location 'http://localhost:3001/rpc' \
--header 'master-api-key: example_key' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "command.create",
"id": "Employee",
"params": {
"data": {
"name": "Alice",
"email": "[email protected]",
"code": "EMP001"
}
}
}'
command.sync{
"jsonrpc": "2.0",
"method": "command.sync",
"id": "All",
"params": {
"alter": true
}
}
command.create{
"jsonrpc": "2.0",
"method": "command.bulkCreate",
"id": "Employee",
"params": {
"data": {
"name": "Alice",
"email": "[email protected]",
"department_id": "687d4262-cccf-4d7d-a06d-31034777fa03",
"code": "EMP001"
}
}
}
command.bulkCreate{
"jsonrpc": "2.0",
"method": "command.bulkCreate",
"id": "Employee",
"params": {
"data": [
{
"name": "Alice",
"email": "[email protected]",
"department_id": "687d4262-cccf-4d7d-a06d-31034777fa03",
"code": "EMP001"
},
{
"name": "Bob",
"email": "[email protected]",
"department_id": "cf17582b-9d0c-48df-ad3b-d22ee1bd0c5d",
"code": "EMP002"
},
{
"name": "Charlie",
"email": "[email protected]",
"department_id": "687d4262-cccf-4d7d-a06d-31034777fa03",
"code": "EMP003"
}
]
}
}
command.update{
"jsonrpc": "2.0",
"method": "command.update",
"id": "Employee",
"params": {
"data": {
"name": "Alice Lastname",
"email": "[email protected]"
},
"where": {
"id:": "8d1803d9-23cb-4673-bd24-bcd8d02c147b"
}
}
}
command.destroy{
"jsonrpc": "2.0",
"method": "command.destroy",
"id": "Employee",
"params": {
"where": {
"id:": "8d1803d9-23cb-4673-bd24-bcd8d02c147b"
}
}
}
command.removeCache{
"jsonrpc": "2.0",
"method": "command.destroy",
"id": "Employee"
}
command.restore{
"jsonrpc": "2.0",
"method": "command.restore",
"id": "Employee",
"params": {
"where": {
"id:": "8d1803d9-23cb-4673-bd24-bcd8d02c147b"
}
}
}
query.findOnequery.findAllquery.findAndCountAllcurl --location 'http://localhost:3001/rpc' \
--header 'master-api-key: example_key' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "query.findAll",
"id": "Employee",
"params": {
"attributes": ["code", "name", "email"],
"include": [
{
"model": "Task",
"attributes": ["name"],
"include": [
{
"model": "Project",
"attributes": ["name"]
}
]
},
{
"model": "Department",
"attributes": ["name"]
}
]
}
}'
Request{
"jsonrpc": "2.0",
"method": "query.findAll",
"id": "Employee",
"params": {
"attributes": ["code", "name", "email"],
"include": [
{
"model": "Task",
"attributes": ["name"],
"include": [
{
"model": "Project",
"attributes": ["name"]
}
]
},
{
"model": "Department",
"attributes": ["name"]
}
]
}
}
Response{
"jsonrpc": "2.0",
"method": "query.findAll",
"id": "Employee",
"result": {
"success": true,
"data": [
{
"code": "EMP001",
"name": "Alice",
"email": "[email protected]",
"Task": [
{
"name": "Campaign Strategy",
"Project": {
"name": "Ad Campaign"
}
}
],
"Department": {
"name": "Sales"
}
},
{
"code": "EMP002",
"name": "Bob",
"email": "[email protected]",
"Task": [
{
"name": "Design Prototypes",
"Project": {
"name": "Product Launch"
}
}
],
"Department": {
"name": "Marketing"
}
},
{
"code": "EMP003",
"name": "Charlie",
"email": "[email protected]",
"Task": [
{
"name": "Market Research",
"Project": {
"name": "Ad Campaign"
}
}
],
"Department": {
"name": "Sales"
}
}
],
"code": 200
}
}
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details.
Content type
Image
Digest
sha256:da29899b0…
Size
204.3 MB
Last updated
almost 3 years ago
docker pull potatodeveloper/jsonrpc-dblink