:rocket: One command to generate REST APIs for any MySql Database.

Overview

npm version Build Status GitHub stars GitHub license

Xmysql : One command to generate REST APIs for any MySql database

Why this ?

xmysql gif

Generating REST APIs for a MySql database which does not follow conventions of frameworks such as rails, django, laravel etc is a small adventure that one like to avoid ..

Hence this.

Setup and Usage

xmysql requires node >= 7.6.0

npm install -g xmysql
xmysql -h localhost -u mysqlUsername -p mysqlPassword -d databaseName
http://localhost:3000

That is it! Simple and minimalistic!

Happy hackery!

Example : Generate REST APIs for Magento

Powered by popular node packages : (express, mysql) => { xmysql }

xmysql gif

Boost Your Hacker Karma By Sharing :

Features

  • Generates API for ANY MySql database 🔥 🔥
  • Serves APIs irrespective of naming conventions of primary keys, foreign keys, tables etc 🔥 🔥
  • Support for composite primary keys 🔥 🔥
  • REST API Usual suspects : CRUD, List, FindOne, Count, Exists, Distinct
  • Bulk insert, Bulk delete, Bulk read 🔥
  • Relations
  • Pagination
  • Sorting
  • Column filtering - Fields 🔥
  • Row filtering - Where 🔥
  • Aggregate functions
  • Group By, Having (as query params) 🔥 🔥
  • Group By, Having (as a separate API) 🔥 🔥
  • Multiple group by in one API 🔥 🔥 🔥 🔥
  • Chart API for numeric column 🔥 🔥 🔥 🔥 🔥 🔥
  • Auto Chart API - (a gift for lazy while prototyping) 🔥 🔥 🔥 🔥 🔥 🔥
  • XJOIN - (Supports any number of JOINS) 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥
  • Supports views
  • Prototyping (features available when using local MySql server only)
    • Run dynamic queries 🔥 🔥 🔥
    • Upload single file
    • Upload multiple files
    • Download file
  • Health and version apis
  • Use more than one CPU Cores
  • Docker support and Nginx reverse proxy config 🔥 🔥 🔥 - Thanks to @markuman
  • AWS Lambda Example - Thanks to @bertyhell 🔥 🔥 🔥

Use HTTP clients like Postman or similar tools to invoke REST API calls


Download node, mysql (setup mysql), sample database - if you haven't on your system.

API Overview

HTTP Type API URL Comments
GET / Gets all REST APIs
GET /api/tableName Lists rows of table
POST /api/tableName Create a new row
PUT /api/tableName Replaces existing row with new row
POST 🔥 /api/tableName/bulk Create multiple rows - send object array in request body
GET 🔥 /api/tableName/bulk Lists multiple rows - /api/tableName/bulk?_ids=1,2,3
DELETE 🔥 /api/tableName/bulk Deletes multiple rows - /api/tableName/bulk?_ids=1,2,3
GET /api/tableName/:id Retrieves a row by primary key
PATCH /api/tableName/:id Updates row element by primary key
DELETE /api/tableName/:id Delete a row by primary key
GET /api/tableName/findOne Works as list but gets single record matching criteria
GET /api/tableName/count Count number of rows in a table
GET /api/tableName/distinct Distinct row(s) in table - /api/tableName/distinct?_fields=col1
GET /api/tableName/:id/exists True or false whether a row exists or not
GET /api/parentTable/:id/childTable Get list of child table rows with parent table foreign key
GET 🔥 /api/tableName/aggregate Aggregate results of numeric column(s)
GET 🔥 /api/tableName/groupby Group by results of column(s)
GET 🔥 /api/tableName/ugroupby Multiple group by results using one call
GET 🔥 /api/tableName/chart Numeric column distribution based on (min,max,step) or(step array) or (automagic)
GET 🔥 /api/tableName/autochart Same as Chart but identifies which are numeric column automatically - gift for lazy while prototyping
GET 🔥 /api/xjoin handles join
GET 🔥 /dynamic execute dynamic mysql statements with params
GET 🔥 /upload upload single file
GET 🔥 /uploads upload multiple files
GET 🔥 /download download a file
GET /api/tableName/describe describe each table for its columns
GET /api/tables get all tables in database
GET /_health gets health of process and mysql -- details query params for more details
GET /_version gets version of Xmysql, mysql, node

Relational Tables

xmysql identifies foreign key relations automatically and provides GET api.

/api/blogs/103/comments

eg: blogs is parent table and comments is child table. API invocation will result in all comments for blog primary key 103. ⤴️

Support for composite primary keys

___ (three underscores)

/api/payments/103___JM555205

___ : If there are multiple primary keys - separate them by three underscores as shown

Pagination

_p & _size

_p indicates page and _size indicates size of response rows

By default 20 records and max of 100 are returned per GET request on a table.

/api/payments?_size=50
/api/payments?_p=2
/api/payments?_p=2&_size=50

When _size is greater than 100 - number of records defaults to 100 (i.e maximum)

When _size is less than or equal to 0 - number of records defaults to 20 (i.e minimum)

Order by / Sorting

ASC

/api/payments?_sort=column1

eg: sorts ascending by column1

DESC

/api/payments?_sort=-column1

eg: sorts descending by column1

Multiple fields in sort

/api/payments?_sort=column1,-column2

eg: sorts ascending by column1 and descending by column2

Column filtering / Fields

/api/payments?_fields=customerNumber,checkNumber

eg: gets only customerNumber and checkNumber in response of each record

/api/payments?_fields=-checkNumber

eg: gets all fields in table row but not checkNumber

Row filtering / Where

Comparison operators

eq      -   '='         -  (colName,eq,colValue)
ne      -   '!='        -  (colName,ne,colValue)
gt      -   '>'         -  (colName,gt,colValue)
gte     -   '>='        -  (colName,gte,colValue)
lt      -   '<'         -  (colName,lt,colValue)
lte     -   '<='        -  (colName,lte,colValue)
is      -   'is'        -  (colName,is,true/false/null)
in      -   'in'        -  (colName,in,val1,val2,val3,val4)
bw      -   'between'   -  (colName,bw,val1,val2) 
like    -   'like'      -  (colName,like,~name)   note: use ~ in place of % 
nlike   -   'not like'  -  (colName,nlike,~name)  note: use ~ in place of %

Use of comparison operators

/api/payments?_where=(checkNumber,eq,JM555205)~or((amount,gt,200)~and(amount,lt,2000))

Logical operators

~or     -   'or'
~and    -   'and'
~xor    -   'xor'

Use of logical operators

eg: simple logical expression

/api/payments?_where=(checkNumber,eq,JM555205)~or(checkNumber,eq,OM314933)

eg: complex logical expression

/api/payments?_where=((checkNumber,eq,JM555205)~or(checkNumber,eq,OM314933))~and(amount,gt,100)

eg: logical expression with sorting(_sort), pagination(_p), column filtering (_fields)

/api/payments?_where=(amount,gte,1000)&_sort=-amount&p=2&_fields=customerNumber

eg: filter of rows using _where is available for relational route URLs too.

/api/offices/1/employees?_where=(jobTitle,eq,Sales%20Rep)

FindOne

/api/tableName/findOne?_where=(id,eq,1)

Works similar to list but only returns top/one result. Used in conjunction with _where ⤴️

Count

/api/tableName/count

Returns number of rows in table ⤴️

Exists

/api/tableName/1/exists

Returns true or false depending on whether record exists ⤴️

Group By Having as query params

⤴️

/api/offices?_groupby=country

eg: SELECT country,count(*) FROM offices GROUP BY country

/api/offices?_groupby=country&_having=(_count,gt,1)

eg: SELECT country,count(1) as _count FROM offices GROUP BY country having _count > 1

Group By Having as API

⤴️

/api/offices/groupby?_fields=country

eg: SELECT country,count(*) FROM offices GROUP BY country

/api/offices/groupby?_fields=country,city

eg: SELECT country,city,count(*) FROM offices GROUP BY country,city

/api/offices/groupby?_fields=country,city&_having=(_count,gt,1)

eg: SELECT country,city,count(*) as _count FROM offices GROUP BY country,city having _count > 1

Group By, Order By

⤴️

/api/offices/groupby?_fields=country,city&_sort=city

eg: SELECT country,city,count(*) FROM offices GROUP BY country,city ORDER BY city ASC

/api/offices/groupby?_fields=country,city&_sort=city,country

eg: SELECT country,city,count(*) FROM offices GROUP BY country,city ORDER BY city ASC, country ASC

/api/offices/groupby?_fields=country,city&_sort=city,-country

eg: SELECT country,city,count(*) FROM offices GROUP BY country,city ORDER BY city ASC, country DESC

Aggregate functions

⤴️

http://localhost:3000/api/payments/aggregate?_fields=amount

response body
[
    {
        "min_of_amount": 615.45,
        "max_of_amount": 120166.58,
        "avg_of_amount": 32431.645531,
        "sum_of_amount": 8853839.23,
        "stddev_of_amount": 20958.625377426568,
        "variance_of_amount": 439263977.71130896
    }
]

eg: retrieves all numeric aggregate of a column in a table

http://localhost:3000/api/orderDetails/aggregate?_fields=priceEach,quantityOrdered

response body
[
    {
        "min_of_priceEach": 26.55,
        "max_of_priceEach": 214.3,
        "avg_of_priceEach": 90.769499,
        "sum_of_priceEach": 271945.42,
        "stddev_of_priceEach": 36.576811252187795,
        "variance_of_priceEach": 1337.8631213781719,
        "min_of_quantityOrdered": 6,
        "max_of_quantityOrdered": 97,
        "avg_of_quantityOrdered": 35.219,
        "sum_of_quantityOrdered": 105516,
        "stddev_of_quantityOrdered": 9.832243813502942,
        "variance_of_quantityOrdered": 96.67301840816688
    }
]

eg: retrieves numeric aggregate can be done for multiple columns too

Union of multiple group by statements

⤴️

🔥 🔥 [ HOTNESS ALERT ]

Group by multiple columns in one API call using _fields query params - comes really handy

http://localhost:3000/api/employees/ugroupby?_fields=jobTitle,reportsTo

response body
{  
   "jobTitle":[  
      {  
         "Sales Rep":17
      },
      {  
         "President":1
      },
      {  
         "Sale Manager (EMEA)":1
      },
      {  
         "Sales Manager (APAC)":1
      },
      {  
         "Sales Manager (NA)":1
      },
      {  
         "VP Marketing":1
      },
      {  
         "VP Sales":1
      }
   ],
   "reportsTo":[  
      {  
         "1002":2
      },
      {  
         "1056":4
      },
      {  
         "1088":3
      },
      {  
         "1102":6
      },
      {  
         "1143":6
      },
      {  
         "1621":1
      }
      {  
         "":1
      },
   ]
}

Chart

⤴️

🔥 🔥 🔥 🔥 🔥 🔥 [ HOTNESS ALERT ]

Chart API returns distribution of a numeric column in a table

It comes in SEVEN powerful flavours

  1. Chart : With min, max, step in query params 🔥 🔥 ⤴️

This API returns the number of rows where amount is between (0,25000), (25001,50000) ...

/api/payments/chart?_fields=amount&min=0&max=131000&step=25000

Response

[
  {
    "amount": "0 to 25000",
    "_count": 107
  },
  {
    "amount": "25001 to 50000",
    "_count": 124
  },
  {
    "amount": "50001 to 75000",
    "_count": 30
  },
  {
    "amount": "75001 to 100000",
    "_count": 7
  },
  {
    "amount": "100001 to 125000",
    "_count": 5
  },
  {
    "amount": "125001 to 150000",
    "_count": 0
  }
]

  1. Chart : With step array in params 🔥 🔥 ⤴️

This API returns distribution between the step array specified

/api/payments/chart?_fields=amount&steparray=0,10000,20000,70000,140000

Response

[
  {
    "amount": "0 to 10000",
    "_count": 42
  },
  {
    "amount": "10001 to 20000",
    "_count": 36
  },
  {
    "amount": "20001 to 70000",
    "_count": 183
  },
  {
    "amount": "70001 to 140000",
    "_count": 12
  }
]


  1. Chart : With step pairs in params 🔥 🔥 ⤴️

This API returns distribution between each step pair

/api/payments/chart?_fields=amount&steppair=0,50000,40000,100000

Response

[
    {"amount":"0 to 50000","_count":231},
    {"amount":"40000 to 100000","_count":80}
]


  1. Chart : with no params 🔥 🔥 ⤴️

This API figures out even distribution of a numeric column in table and returns the data

/api/payments/chart?_fields=amount

Response
[
  {
    "amount": "-9860 to 11100",
    "_count": 45
  },
  {
    "amount": "11101 to 32060",
    "_count": 91
  },
  {
    "amount": "32061 to 53020",
    "_count": 109
  },
  {
    "amount": "53021 to 73980",
    "_count": 16
  },
  {
    "amount": "73981 to 94940",
    "_count": 7
  },
  {
    "amount": "94941 to 115900",
    "_count": 3
  },
  {
    "amount": "115901 to 130650",
    "_count": 2
  }
]

  1. Chart : range, min, max, step in query params 🔥 🔥 ⤴️

This API returns the number of rows where amount is between (0,25000), (0,50000) ... (0,maxValue)

Number of records for amount is counted from min value to extended Range instead of incremental steps

/api/payments/chart?_fields=amount&min=0&max=131000&step=25000&range=1

Response

[
   {
       "amount": "0 to 25000",
       "_count": 107
   },
   {
       "amount": "0 to 50000",
       "_count": 231
   },
   {
       "amount": "0 to 75000",
       "_count": 261
   },
   {
       "amount": "0 to 100000",
       "_count": 268
   },
   {
       "amount": "0 to 125000",
       "_count": 273
   }
]

  1. Range can be specified with step array like below
/api/payments/chart?_fields=amount&steparray=0,10000,20000,70000,140000&range=1

[
   {
       "amount": "0 to 10000",
       "_count": 42
   },
   {
       "amount": "0 to 20000",
       "_count": 78
   },
   {
       "amount": "0 to 70000",
       "_count": 261
   },
   {
       "amount": "0 to 140000",
       "_count": 273
   }
]
  1. Range can be specified without any step params like below
/api/payments/chart?_fields=amount&range=1

[
    {
        "amount": "-9860 to 11100",
        "_count": 45
    },
    {
        "amount": "-9860 to 32060",
        "_count": 136
    },
    ...
    
]

Please Note: _fields in Chart API can only take numeric column as its argument.

Autochart

Identifies numeric columns in a table which are not any sort of key and applies chart API as before - feels like magic when there are multiple numeric columns in table while hacking/prototyping and you invoke this API.

http://localhost:3000/api/payments/autochart

[
    {
        "column": "amount",
        "chart": [
                    {
                        "amount": "-9860 to 11100",
                        "_count": 45
                    },
                    {
                        "amount": "11101 to 32060",
                        "_count": 91
                    },
                    {
                        "amount": "32061 to 53020",
                        "_count": 109
                    },
                    {
                        "amount": "53021 to 73980",
                        "_count": 16
                    },
                    {
                        "amount": "73981 to 94940",
                        "_count": 7
                    },
                    {
                        "amount": "94941 to 115900",
                        "_count": 3
                    },
                    {
                        "amount": "115901 to 130650",
                        "_count": 2
                    }
                ]
    }
]

XJOIN

Xjoin query params and values:

_join           :   List of tableNames alternated by type of join to be made (_j, _ij,_ lj, _rj)
alias.tableName :   TableName as alias
_j              :   Join [ _j => join, _ij => ij, _lj => left join , _rj => right join)
_onNumber       :   Number 'n' indicates condition to be applied for 'n'th join between (n-1) and 'n'th table in list  

Simple example of two table join:

Sql join query:

SELECT pl.field1, pr.field2
FROM productlines as pl
    JOIN products as pr
        ON pl.productline = pr.productline

Equivalent xjoin query API:

/api/xjoin?_join=pl.productlines,_j,pr.products&_on1=(pl.productline,eq,pr.productline)&_fields=pl.field1,pr.field2

Multiple tables join

Sql join query:

SELECT pl.field1, pr.field2, ord.field3
FROM productlines as pl
    JOIN products as pr
        ON pl.productline = pr.productline
    JOIN orderdetails as ord
        ON pr.productcode = ord.productcode

Equivalent xjoin query API:

/api/xjoin?_join=pl.productlines,_j,pr.products,_j,ord.orderDetails&_on1=(pl.productline,eq,pr.productline)&_on2=(pr.productcode,eq,ord.productcode)&_fields=pl.field1,pr.field2,ord.field3

Explanation:

pl.productlines => productlines as pl

_j => join

pr.products => products as pl

_on1 => join condition between productlines and products => (pl.productline,eq,pr.productline)

_on2 => join condition between products and orderdetails => (pr.productcode,eq,ord.productcode)

Example to use : _fields, _where, _p, _size in query params

/api/xjoin?_join=pl.productlines,_j,pr.products&_on1=(pl.productline,eq,pr.productline)&_fields=pl.productline,pr.productName&_size=2&_where=(productName,like,1972~)

Response:

[{"pl_productline":"Classic Cars","pr_productName":"1972 Alfa Romeo GTA"}]

Please note : Xjoin response has aliases for fields like below aliasTableName + '_' + columnName.
eg: pl.productline in _fields query params - returns as pl_productline in response.

Run dynamic queries

⤴️

Dynamic queries on a database can be run by POST method to URL localhost:3000/dynamic

This is enabled ONLY when using local mysql server i.e -h localhost or -h 127.0.0.1 option.

Post body takes two fields : query and params.

query: SQL query or SQL prepared query (ones with ?? and ?)

params : parameters for SQL prepared query

POST /dynamic   

    {
        "query": "select * from ?? limit 1,20",
        "params": ["customers"]
    }

POST /dynamic URL can have any suffix to it - which can be helpful in prototyping

eg:

POST /dynamic/weeklyReport
POST /dynamic/user/update

Upload single file

⤴️

POST /upload

Do POST operation on /upload url with multiform 'field' assigned to local file to be uploaded

eg: curl --form file=@/Users/me/Desktop/a.png http://localhost:3000/upload

returns uploaded file name else 'upload failed'

(Note: POSTMAN has issues with file uploading hence examples with curl)

Upload multiple files

⤴️

POST /uploads

Do POST operation on /uploads url with multiform 'fields' assigned to local files to be uploaded

Notice 's' near /api/uploads and files in below example

eg: curl --form files=@/Users/me/Desktop/a.png --form files=@/Users/me/Desktop/b.png http://localhost:3000/uploads

returns uploaded file names as string

Download file

⤴️

http://localhost:3000/download?name=fileName

For upload and download of files -> you can specify storage folder using -s option Upload and download apis are available only with local mysql server

Health

⤴️

http://localhost:3000/_health

{"process_uptime":3.858,"mysql_uptime":"2595"}

Shows up time of Xmysql process and mysql server

http://localhost:3000/_health?details=1

{"process_uptime":1.151,"mysql_uptime":"2798",
"os_total_memory":17179869184,
"os_free_memory":2516357120,
"os_load_average":[2.29931640625,2.1845703125,2.13818359375],
"v8_heap_statistics":{"total_heap_size":24735744,
"total_heap_size_executable":5242880,
"total_physical_size":23521048,
"total_available_size":1475503064,
"used_heap_size":18149064,
"heap_size_limit":1501560832,
"malloced_memory":8192,
"peak_malloced_memory":11065664,
"does_zap_garbage":0}}

Provides more details on process.

Infact passing any query param gives detailed health output: example below

http://localhost:3000/_health?voila

{"process_uptime":107.793,"mysql_uptime":"2905","os_total_memory":17179869184,"os_free_memory":2573848576,"os_load_average":[2.052734375,2.12890625,2.11767578125],"v8_heap_statistics":{"total_heap_size":24735744,"total_heap_size_executable":5242880,"total_physical_size":23735016,"total_available_size":1475411128,"used_heap_size":18454968,"heap_size_limit":1501560832,"malloced_memory":8192,"peak_malloced_memory":11065664,"does_zap_garbage":0}}

Version

⤴️

http://localhost:3000/_version

{"Xmysql":"0.4.1","mysql":"5.7.15","node":"8.2.1"}

When to use ?

⤴️

  • You need just REST APIs for (ANY) MySql database at blink of an eye (literally).
  • You are learning new frontend frameworks and need REST APIs for your MySql database.
  • You are working on a demo, hacks etc

When NOT to use ?

⤴️

  • If you are in need of a full blown MVC framework, ACL, Validations, Authorisation etc - its early days please watch/star this repo to keep a tab on progress.

Command line options

⤴️

  Options:

    -V, --version            Output the version number
    -h, --host <n>           Hostname of database -> localhost by default
    -u, --user <n>           Username of database -> root by default
    -p, --password <n>       Password of database -> empty by default
    -d, --database <n>       database schema name
    -r, --ipAddress <n>      IP interface of your server / localhost by default    
    -n, --portNumber <n>     Port number for app -> 3000 by default
    -o, --port <n>           Port number of mysql -> 3306 by default
    -a, --apiPrefix <n>      Api url prefix -> /api/ by default
    -s, --storageFolder <n>  Storage folder -> current working dir by default (available only with local)
    -i, --ignoreTables <n>   Comma separated table names to ignore
    -c, --useCpuCores <n>    Specify number of cpu cores to use / 1 by default / 0 to use max
    -y, --readOnly           readonly apis -> false by default    
    -h, --help               Output usage information

    
  Examples:

    $ xmysql -u username -p password -d databaseSchema

Boost Your Hacker Karma By Sharing :

Docker

⤴️

Simply run with docker run -p 3000:80 -d markuman/xmysql:0.4.2

The best way for testing is to run mysql in a docker container too and create a docker network, so that xmysql can access the mysql container with a name from docker network.

  1. Create network
    • docker network create mynet
  2. Start mysql with docker name some-mysql and bind to docker network mynet
    • docker run --name some-mysql -p 3306:3306 --net mynet -e MYSQL_ROOT_PASSWORD=password -d markuman/mysql
  3. run xmysql and set env variable for some-mysql from step 2
    • docker run -p 3000:80 -d -e DATABASE_HOST=some-mysql --net mynet markuman/xmysql

You can also pass the environment variables to a file and use them as an option with docker like docker run --env-file ./env.list -p 3000:80 --net mynet -d markuman/xmysql

environment variables which can be used:

ENV DATABASE_HOST 127.0.0.1
ENV DATABASE_USER root
ENV DATABASE_PASSWORD password
ENV DATABASE_NAME sakila

Furthermore, the docker container of xmysql is listen on port 80. You can than request it just with http://xmysql/api/ in other services running in the same docker network.

Debugging xmysql in docker.

Given you've deployed your xmysql docker container like

docker run -d \
--network local_dev \
--name xmysql \
-p 3000:80 \
-e DATABASE_HOST=mysql_host \
-e DATABASE_USER=root \
-e DATABASE_PASSWORD=password \
-e DATABASE_NAME=sys \
markuman/xmysql:0.4.2

but the response is just

["http://127.0.0.1:3000/api/tables","http://127.0.0.1:3000/api/xjoin"]

then obviously the connection to your mysql database failed.

  1. attache to the xmysql image
    • docker exec -ti xmysql
  2. install mysql cli client
    • apk --update --no-cache add mysql-client
  3. try to access your mysql database
    • mysql-client -h mysql_host
  4. profit from the mysql-client error output and improve the environment variables for mysql

Nginx Reverse Proxy Config with Docker

⤴️

This is a config example when you use nginx as reverse proxy

events {
   worker_connections 1024;
   
}
http {
    server {
        server_name 127.0.0.1;
        listen 80 ;
        location / {
            rewrite ^/(.*) /$1 break;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:3000;
        }
    }
}

e.g.

  1. create a docker network docker network create local_dev
  2. start a mysql server docker run -d --name mysql -p 3306:3306 --network local_dev -e MYSQL_ROOT_PASSWORD=password mysql
  3. start xmysql docker run -d --network local_dev --name xmyxql -e DATABASE_NAME=sys -e DATABASE_HOST=mysql -p 3000:80 markuman/xmysql:0.4.2
  4. start nginx on host system with the config above sudo nginx -g 'daemon off;' -c /tmp/nginx.conf
  5. profit curl http://127.0.0.1/api/host_summary_by_file_io_type/describe

When you start your nginx proxy in a docker container too, use as proxy_pass the --name value of xmysql. E.g. proxy_pass http://xmysql (remember, xmysql runs in it's docker container already on port 80).

Tests : setup on local machine

⤴️

docker-compose run test
  • Requires docker-compose to be installed on your machine.
Comments
  • This npm only working windows os, not working in ubuntu...

    This npm only working windows os, not working in ubuntu...

    Please provide dev environment versions of your system

    node -v ( xmysql requires node >= 7.6.0 )

    npm -v mysql --version xmysql --version


    Provide steps to reproduce this issue or Provide minimum code to reproduce this issue or HTTP request,response,error snapshot of this issue


    Mark issue with suitable label if it is clear what this issue is.

    opened by Goopps 0
  • better to support emoji charset parameter

    better to support emoji charset parameter

    xmysql is a great tool for automation , thanks a lot of sharing. and when play with it, i found it's not able to pass charset parameter 😆

    .option("-charset, --charset ", "charset support emoji")

    opened by PpAaLlMmEeRr 0
  • No Support for Timezone In xMySQL

    No Support for Timezone In xMySQL

    In NodeJS, when a connection is initialized for mysql, the default timezone is 'UTC' If the data stored in the database is not in UTC timezone then when xMySQL fetches the data then the same DateTime is not received. xMySQL returns the UTC time by converting the local time stored in DB to UTC timezone.

    Eg: My time zone is IST (->UTC +5:30) data in db = "2022-02-01" <- The data is stored in IST TimeZone data i get from xMySQL = "2022-01-31T18:30:00.000Z" <- See the offset of -5:30 due to timezone not set properly

    Solution: I cloned the repo and found a solution for this. The following command line argument can be added, so timezone can also be supported by xMySQL.

    cmd.helper.js-> [near line 74] program.timezone = program.timezone || "UTC"; //default to UTC if no timezone provided

    [near line 19] .option("-t, --timezone ", "set the timezone")

    adding this will cause the code to add the timzone parameter in the "sqlConfig".

    Internally it would end up like this: var sqlConfig= { host : 'localhost', user : 'xxx', password : '', database : 'xxx', timezone: 'IST' //<-the timzone added after the above code change };

    Comment on this Issue if you choose to use these changes. Will improve my quality of life

    opened by ShantanuVidwans 0
  • xmysql rest api - CORS support

    xmysql rest api - CORS support

    Please provide dev environment versions of your system

    node -v ( xmysql requires node >= 7.6.0 ) = v14.17.2 npm -v = 7.24.1 mysql --version = mysql Ver 8.0.26 for macos11.3 on x86_64 (Homebrew) xmysql --version = undefined

    Tried to connect the generated APIs to Angular UI, CORS blocks requests.

    Access to XMLHttpRequest at 'localhost:3000/api/consultant' from origin 'http://localhost:4200' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

    opened by impondesk 1
  • SSL connection error

    SSL connection error

    @o1lab , Once i've been trying to connect via cli to the external DBserver, got the following error: As according to the error seems that the connection been executed properly but there is additional parameter missing. Could you please advice?

    ` Generating REST APIs at the speed of your thought..

    Cache init failed during database reading Error: UNKNOWN_CODE_PLEASE_REPORT: SSL connection is required. Please specify SSL options and retry. at Handshake.Sequence._packetToError (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14) at Handshake.ErrorPacket (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18) at Protocol._parsePacket (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\Protocol.js:291:23) at Parser._parsePacket (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\Parser.js:433:10) at Parser.write (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\Parser.js:43:10) at Protocol.write (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\Protocol.js:38:16) at Socket. (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\Connection.js:88:28) at Socket. (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\Connection.js:526:10) at Socket.emit (events.js:310:20) at addChunk (_stream_readable.js:286:12) -------------------- at Protocol._enqueue (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\Protocol.js:144:48) at Protocol.handshake (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\protocol\Protocol.js:51:23) at PoolConnection.connect (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\Connection.js:116:18) at Pool.getConnection (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\Pool.js:48:16) at Pool.query (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\node_modules\mysql\lib\Pool.js:202:8) at Xsql.dbCacheInitAsync (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\lib\xsql.js:31:15) at Xsql.init (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\lib\xsql.js:23:10) at Xapi.init (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\lib\xapi.js:35:16) at startXmysql (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\bin\index.js:42:12) at start (C:\Users\Stas\AppData\Roaming\npm\node_modules\xmysql\bin\index.js:89:5) { code: 'UNKNOWN_CODE_PLEASE_REPORT', errno: 9002, sqlMessage: 'SSL connection is required. Please specify SSL options and retry.\u0000', sqlState: '28000', fatal: true } undefined`

    opened by Totti10as 0
  • Can't  connect in docker via 2 container

    Can't connect in docker via 2 container

    using docker in the description

    docker run -d
    --network local_dev
    --name xmysql
    -p 4000:80
    -e DATABASE_HOST=mysql_host
    -e DATABASE_USER=root
    -e DATABASE_PASSWORD=password
    -e DATABASE_NAME=sys
    markuman/xmysql:0.4.2

    after docker run it, i could access xmysql on localhost:### 4000

    But the result in http://localhost:4000/api/tables , can't connect to DB.

    { "error": { "code": "ECONNREFUSED", "errno": "ECONNREFUSED", "syscall": "connect", "address": "127.0.0.1", "port": 3306, "fatal": true } }

    For my mysql service, I create in other container. for my desktop, I could connect mysql service in MySQL Workbench with the same db username and password.


    Does anyone know how to set the network on the docker? 1 container -> xmysql 1 container -> mysql

    image

    opened by simonlkch 0
Releases(0.4.9)
Owner
Creator XgeneCloud
null
Social-Feeds-APIs - REST APIs to build social media sites.

express4.17.1-in-docker EXPRESS 4.17 SPA IMPORTANT NOTES: 1. Make sure you follow the steps mentioned under "PROJECT START STEPS" and ensure that the

Patel Rohan 1 Jan 3, 2022
Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

Database manager for MySQL, PostgreSQL, SQL Server, MongoDB, SQLite and others. Runs under Windows, Linux, Mac or as web application

DbGate 2k Dec 30, 2022
Lovefield is a relational database for web apps. Written in JavaScript, works cross-browser. Provides SQL-like APIs that are fast, safe, and easy to use.

Lovefield Lovefield is a relational database written in pure JavaScript. It provides SQL-like syntax and works cross-browser (currently supporting Chr

Google 6.8k Jan 3, 2023
🔥 Dreamy-db - A Powerful database for storing, accessing, and managing multiple database.

Dreamy-db About Dreamy-db - A Powerful database for storing, accessing, and managing multiple databases. A powerful node.js module that allows you to

Dreamy Developer 24 Dec 22, 2022
DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB database, such as: connecting to the database, executing scripts, calling functions, uploading variables, etc.

DolphinDB JavaScript API English | 中文 Overview DolphinDB JavaScript API is a JavaScript library that encapsulates the ability to operate the DolphinDB

DolphinDB 6 Dec 12, 2022
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.

TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used

null 30.1k Jan 3, 2023
A query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.

knex.js A SQL query builder that is flexible, portable, and fun to use! A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle

knex 16.9k Jan 4, 2023
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Bookshelf.js 6.3k Jan 2, 2023
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite datab

MikroORM 5.4k Dec 31, 2022
A pure node.js JavaScript Client implementing the MySQL protocol.

mysql Table of Contents Install Introduction Contributors Sponsors Community Establishing connections Connection options SSL options Connection flags

null 17.6k Jan 1, 2023
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server & SQLite

Prisma Quickstart • Website • Docs • Examples • Blog • Slack • Twitter • Prisma 1 What is Prisma? Prisma is a next-generation ORM that consists of the

Prisma 28k Jan 2, 2023
An adapter-based ORM for Node.js with support for mysql, mongo, postgres, mssql (SQL Server), and more

Waterline is a next-generation storage and retrieval engine, and the default ORM used in the Sails framework. It provides a uniform API for accessing

Balderdash 5.4k Jan 4, 2023
This is a demo sample of linking NODEJS via ORM and MYSQL

Demons(Demo of Nodejs with SQL) This is a demo sample of linking NODEJS with ORM and MYSQL Connecting Node to SQL is a hard task and not much help is

Shivam Sourav Jha 3 Apr 14, 2022
NodeJS,express and mysql starter project

Node-express-mysql-starterproject NodeJS,express and mysql starter project Start with cloning the repo & Run npm i to download all the dependecies Aft

Nermine slimane 16 Dec 11, 2022
A MySQL Library for Node.js

A MySQL Library for Node.js

Blaze Rowland 3 Mar 14, 2022
A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.

Dittorm A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud. Installatio

Waline 21 Dec 25, 2022
Create flexible REST endpoints and controllers from Sequelize models in your Express app

Finale Create flexible REST endpoints and controllers from Sequelize models in your Express or Restify app. This project aims to be a Sequelize 4.x an

Tom Juszczyk 181 Oct 18, 2022
A javascript REST ORM that is offline and real-time capable

Rekord Rekord is an ORM - a way to define properties and relationships - that interacts with local storage, a RESTful service, and a real-time service

Rekord 177 Oct 18, 2022