gqb

command module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2019 License: MIT Imports: 16 Imported by: 0

README

gQB

coverage Build Status Go Report Card

The generated Query Builder creates a query builder and if needed a migration using a yaml configuration.

The gqb takes takes the following flags as arguments:

-migrate		Writes the configuration to the specified sql file
			takes the output file as argument

-db			Directly inserts the configured structure as migration
			into the database using the DB_DRIVER and DB_URL enviroment
			variables as flags for this mode

-model			Writes the configruration to git.ultraware.nl/NiseVoid/qb
			models and takes the output as argument

-pkg			Specifies the package name for the qbmodels (default model)

-dvr			Specifies the driver for sql generation (default postgres)

Configuration

Create a configuration file based on the following yaml structure (this is an example configuration):

pkg: models                             # optional
driver: mysql                           # optional (default postgres)
tables:
  users:
    id: int, primary
    email: varchar, unique
    password: varchar
    first_name: varchar(50)
    last_name: varchar(100)
    role: role                          # foreign key (enum)

  posts:
    id: int, primary
    created_by: users.id                # foreign key
    created_at: datetime, default(NOW)
    updated_at: datetime, default(NOW)
    title: varchar
    subtitle: varchar, nullable
    context: text

  images:
    id: int, primary
    title: varchar
    created_at: datetime, default(NOW)
    updated_at: datetime, default(NOW)
    path: varchar

  post_images:
    id: int, primary
    image_id: images.id                 # foreign key
    post_id: posts(id)                  # another foreign key
    description: varchar

enums:
  role:
  - ADMIN
  - MODERATOR
  - GENERAL_USER

The configuration has the following type constraints:

primary			sets the type as primary key in the table
unique			set a UNIQUE constraint on the type
nullable		undoes the default NOT NULL constraint on a type
default(%)		sets the default constraint and uses a parameter to set a default value
constraint(%)		sets one or more constraints, constraints can be seperated using ;

Installation

Install this using go get:

$ go get -u github.com/jobstoit/gqb

Then start using it, try:

$ gqb

Todo

  • Create configuration reader
  • Create SQL generator
  • Create NiseVoid/qb generator
  • Create a database differential inspector (config against the current state of the database)
  • Create a diffential SQL generator & executor
  • Create a seeder & seeder configuration

Documentation

Overview

gqb is made for generating a query builder.

The gqb command takes the path to the db.yml as argument. So for example:

gqb -model ./models/qb.mdl.go db.yml

The command takes the following flags as arguments.

-migrate           Specifies the output for a generated sql migration

-db                Directly inserts the configured structure into the database
                   using the DB_DRIVER and DB_CONNECTION_STRING enviroment
                   variables or the flags for this mode

-dvr               Set the driver for the db flag

-cs                Sets the connection string for the db flag

-model             Writes the configuration to NiseVoid/qb model(s) takes
                   the output file(s) as argument

-pkg               Used by the model flag, sets the package name of the
                   model file(s)

Configuration yaml example.

pkg: models                              # optional, default model
driver: postgres                         # optional, default postgres
tables:
  users:
    id: int, primary
    email: varchar, unique
    password: varhcar
    fist_name: varchar(50)
    last_name: varchar(100)
    role: role                           # foreign key (enum)

  posts:
    id: int, primary
    created_by: users.id                 # foreign key
    created_at: datetime, default(NOW)
    updated_at: datetime, default(NOW)
    title: varchar
    subtitle: varchar, nullable
    context: text

  post_images:
    id: int, primary
    posts_id: posts(id)                  # another foreign key
    img_url: varchar

enums:
  role:
  - GENERAL_USER
  - MODERATOR
  - ADMIN

The configuration has the following type constraints:

primary            sets the type as primary key in the table
unique             sets a UNIQUE constraint on the type
nullable           undoes the default NOT NULL constraint on a type
default(%)         set the default constraint and uses the parameter to set
                   a default value
constraint(%)      sets one or more constraints, constraints can be seperated by ;

Jump to

Keyboard shortcuts

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