🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

github.com/Demitroi/query-builders

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/Demitroi/query-builders

v0.0.0-20200604044442-eb224a2c6104
Source
Go
Version published
Created
Source

query-builders

Example of SQL Query builders in GOlang to create API REST

Build Status codecov Go Report Card

Usage

We need a mysql/mariadb database server. Create a database and the table from dabatase.sql file. Execute indicating the query builder, for example.

$ go run main.go gendry
Now listening on: http://0.0.0.0:1081
Application started. Press CTRL+C to shut down.

There are 3 query builders available.

Also we can pass database params via args.

$ go run main.go --help
query-builder is an example of mysql databases in golang

Usage:
  query-builder [flags] [builder]

Examples:
query-builder gendry
query-builder goqu
query-builder dbx

Flags:
      --database-address string    Database connection address (default "localhost") 
      --database-name string       Database name (default "query_builders")
      --database-password string   Database user password
      --database-port int          Database connection port (default 3306)
      --database-protocol string   Database connection protocol (default "tcp")      
      --database-user string       Database user (default "root")
  -h, --help                       help for query-builder
  -p, --port int                   Port to serve (default 1081)

API

List persons

GET /api/v1/persons

Query string Params

FieldType
idstring
namestring
citystring
birth_date_eqstring
birth_date_gtestring
birth_date_ltestring
weight_eqnumber
weight_gtenumber
weight_ltenumber
height_eqnumber
height_gtenumber
height_ltenumber

Example response

[
  {
    "id": "1",
    "name": "Demitroi Marshall",
    "city": "Ejido Mezquiral",
    "birth_date": "1995-06-07T08:00:00Z",
    "weight": 85,
    "height": 181
  },
  {
    "id": "6",
    "name": "John Cena",
    "city": "Tampa",
    "birth_date": "1977-04-23T08:00:00Z",
    "weight": 112,
    "height": 184
  }
]

Get person

GET /api/v1/persons/:id

Example response

{
  "id":"1",
  "name":"Demitroi Marshall",
  "city":"San Luis Rio Colorado",
  "birth_date":"1995-06-07T08:00:00Z",
  "weight":85,
  "height":181
}

Add person

POST /api/v1/persons

Example request

{
  "name": "John Cena",
  "city": "Tampa",
  "birth_date": "1977-04-23T08:00:00Z",
  "weight": 112,
  "height": 184
}

Example Response

{
  "id": "6"
}

Update person

POST /api/v1/persons/6

Example request

{
  "name": "John Cena",
  "city": "Tampa",
  "birth_date": "1977-04-23T08:00:00Z",
  "weight": 112,
  "height": 184
}

Example Response

{
  "msg": "OK"
}

Delete person

Delete /api/v1/persons/:id

Example response

{
  "msg": "OK"
}

FAQs

Package last updated on 04 Jun 2020

Did you know?

Socket

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.

Install

Related posts