qlfu

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2017 License: MIT Imports: 25 Imported by: 0

README

qlfu

Go Report Card Build StatusCoverage Status

Automated crud restful API on top of ql database.

This allows you to have a quick , fun way to come up with good schema to use for ql database.

ql - refers to ql database https://github.com/cznic/ql

Caveats

  • This is not/ was not intended to be used in production. Stay safe don't try this at work.

  • Don't make concurrent requests. The POST /schema endpoint messes up with the dynamic dispatched endpoint. Please make one API request at a time, this is a better way to use this. PR are welcome though.

  • Starting the server, adding new schema result in a new database. There os no way/intention to reuse the same database. Isn't this fun uh!

features

  • json objects to database schema. Just your normal json objects are auto magically converted to possible ql schema.
  • automatic generation of crud restful json api for the generated schema.
  • seamless building of relationships.One to one, one to many and many to many.
  • comprehensive examples/documentation
  • fun . ql is fun, experiment with it and hopefully you will enjoy it as much as I did.
  • Auto increment id. We use a nice trick to give you unique auto increment id

Installation

go get github.com/gernest/qlfu

This is a command line application, meaning if you did setup properly your GOPATH and added $GOPATH/bin to your system PATH then the binary qlfu should be available in your shell.

[short] Usage

NAME:
   qlfu - magic crud and restful api for experimenting with ql database

USAGE:
   qlfu [global options] command [command options] [arguments...]
   
VERSION:
   0.1.0
   
AUTHOR(S):
   Geofrey Ernest <geofreyernest@live.com> 
   
COMMANDS:
     serve    automated crud & resful api  on ql database
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version

[long] usage

starting the server qlfu serve --dir mydb

Here mydb is the directory which will store ql database files, temporary files wal etc. This directory will be created if it doesn't exist yet.

creating schema
curl -XPOST -H "Content-type: application/json" -d '{
    "user": {
        "username": "gernest",
        "email": "gernest@example.com",
        "profile": {
            "country": "Tanzania",
            "created_at": "Mon Jan 2 15:04:05 2006",
            "updated_at": "Mon Jan 2 15:04:05 2006"
        },
        "created_at": "Mon Jan 2 15:04:05 2006",
        "updated_at": "Mon Jan 2 15:04:05 2006"
    }
}' 'http://localhost:8090/schema'

The objects are normal json objects. The properties of the top level objects will be considered as models from which to build the schema.

Object properties of type number will be mapped to fload64 . You can also have time fields which a string representation of time, for now ANSIC formated time strings are the only one supported, they will map to time ql data type.

viewing the generated schema
curl -XGET 'http://localhost:8090/schema'

which gives you

begin transaction;
   create table profiles (
    id         int64,
    country    string,
    created_at time,
    updated_at time);
   create table users (
    profiles_id int64,
    id          int64,
    username    string,
    email       string,
    created_at  time,
    updated_at  time);
commit;

display the generated api
curl -XGET 'http://localhost:8090/v1'

giving you

{
  "version": "1",
  "Endpoints": [
    {
      "path": "/profiles",
      "params": null,
      "method": "post",
      "payload": "{\"country\":\"country\",\"created_at\":\"Thu Mar  9 11:55:14 2017\",\"updated_at\":\"Thu Mar  9 11:55:14 2017\"}"
    },
    {
      "path": "/profiles",
      "params": null,
      "method": "get",
      "payload": ""
    },
    {
      "path": "/profiles/:id",
      "params": [
        {
          "name": "id",
          "type": "int64",
          "desc": "the id of profiles object",
          "default": 1
        }
      ],
      "method": "get",
      "payload": ""
    },
    {
      "path": "/users",
      "params": null,
      "method": "post",
      "payload": "{\"created_at\":\"Thu Mar  9 11:55:14 2017\",\"email\":\"email\",\"profiles_id\":1,\"updated_at\":\"Thu Mar  9 11:55:14 2017\",\"username\":\"username\"}"
    },
    {
      "path": "/users",
      "params": null,
      "method": "get",
      "payload": ""
    },
    {
      "path": "/users/:id",
      "params": [
        {
          "name": "id",
          "type": "int64",
          "desc": "the id of users object",
          "default": 1
        }
      ],
      "method": "get",
      "payload": ""
    }
  ]
}
create a user with profile
curl -XPOST -H "Content-type: application/json" -d '{"username": "gernest","profile":{"country":"Tanzania"}}' 'http://localhost:8090/v1/users'

giving you

{"id":2,"profile":{"country":"Tanzania","id":1},"profiles_id":1,"username":"gernest"}
get a list of all users
curl -XGET 'http://localhost:8090/v1/users'

which will give you

[{"created_at":null,"email":null,"id":2,"profiles_id":1,"updated_at":null,"username":"gernest"}]
get a user by id
curl -XGET 'http://localhost:8090/v1/users/2'

which will give you

[{"created_at":null,"email":null,"id":2,"profiles_id":1,"updated_at":null,"username":"gernest"}]

TODO

  • populate timestamp fields i.e created_at and updated_at
  • support one to many relationship
  • support many to many relationship
  • improve documentation

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL