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 ;
Click to show internal directories.
Click to hide internal directories.