Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Easily and simply convert SQL database into a REST API with Swagger documentation
Swagger + SQL = Simple reference microservice with transparent documentation and no coding.
All you need to do is create a Swagger file and specify SQL queries in the description.
When you should use it:
Install the appropriate database module before using the SwaggerQL:
pg
for PostgreSQL and Amazon Redshiftmysql2
for MySQLmysql
for MariaDB or MySQLsqlite3
for SQLite3mssql
for MSSQLoracledb
and Oracle instant-client for Oraclenpm install swaggerql
npm install pg
Create config/local.yaml
client: pg
connection:
host: 127.0.0.1
user: your_database_user
password: your_database_password
database: myapp_test
Run SwaggerQL
$(npm bin)/swaggerql
And try http://0.0.0.0:8000
npm install swaggerql
npm install oracledb
Install Oracle instant-client
Create config/local.yaml
client: oracledb
connection:
user: your_database_user
password: your_database_password
connectString: (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SID=MY_SID)))
pool:
min: 0
max: 3
Run SwaggerQL
$(npm bin)/swaggerql
And try http://0.0.0.0:8000
More examples in the repository.
The knex library is used to connect to various databases. The most common configuration file format is:
client: <driver>
connection:
host: 127.0.0.1
user: your_database_user
password: your_database_password
database: myapp_test
More examples of connection configurations in Knex documentation
See node-config documentation for information about naming, load order and format of configuration files.
Build APIs by describing them in OpenAPI document specification and importing them via YAML or JSON to construct your own REST API.
The only difference is that a SQL query is inserted into the description field.
paths:
/two:
get:
summary: One plus one equals two
description: |
SELECT 1 + 1
responses:
200:
description: OK
The description can use Markdown with a specified SQL query:
description: |
Add one to one
```sql
SELECT 1 + 1
```
You can pass parameters to SQL query from path
, query
, form
parameters described in Swagger file.
Use named bindings, such as :name
are interpreted as values and :name:
interpreted as identifiers.
paths:
/increment:
get:
summary: Increment of N per one
description: |
SELECT 1 + :n
parameters:
- name: n
in: query
description: Number
required: true
style: form
explode: true
schema:
type: integer
responses:
200:
description: OK
Query expression can be handled as a transaction if the client sends X-Transaction
header.
Sometimes there's need to release cursors in the database.
paths:
/compute:
get:
summary: Adding the results of a calculation
description: |
insert into table
select function()
parameters:
- name: X-Transaction
in: header
description: Run Query in transaction wrapper
schema:
type: boolean
default: true
Configuration options can be overridden via command-line arguments or environment variables. Priorities are the following:
Run $(npm bin)/swaggerql --help
for more information.
Usage: swaggerql [options]
Options:
-V, --version output the version number
-i, --input-spec <path> path to specification file (default: "openapi.yaml")
-p, --port <number> http port to start server (default: 8000)
-d, --client <name> name of client SQL driver
-c, --connection <dsn|json> connection options to the appropriate database client
-l, --log-level <level> logging level: debug, info, warn, error (default: "info")
-h, --help output usage information
Environment variables:
SWAGGERQL_INPUT_SPEC
— path to specification fileSWAGGERQL_PORT
— http port to start serverSWAGGERQL_CLIENT
— name of client SQL driverSWAGGERQL_CONNECTION
— connection options to the appropriate database clientSWAGGERQL_LOG_LEVEL
— logging leveldocker run -it --rm -p 8000:8000 \
-v $(pwd)/config/local.yaml:/app/config/production.yaml \
-v $(pwd)/openapi.yaml:/app/openapi.yaml \
swaggerql/swaggerql-mysql
Available Docker containers:
0.4.0 — Apr 16, 2020
FAQs
Easily and simply convert SQL database into a REST API with Swagger documentation
The npm package swaggerql receives a total of 3 weekly downloads. As such, swaggerql popularity was classified as not popular.
We found that swaggerql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.