All Projects → qclaogui → database

qclaogui / database

Licence: MIT License
Database SQL builder, written in Go, provides a convenient to creating and running database queries.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to database

Php Es Mapper
An elasticsearch simple mapping ORM for php
Stars: ✭ 25 (-3.85%)
Mutual labels:  builder, query-builder
Loukoum
A simple SQL Query Builder
Stars: ✭ 305 (+1073.08%)
Mutual labels:  builder, query-builder
indexeddb-orm
Indexed DB ORM
Stars: ✭ 53 (+103.85%)
Mutual labels:  builder, query-builder
React Querybuilder
A QueryBuilder component for React
Stars: ✭ 315 (+1111.54%)
Mutual labels:  builder, query-builder
Phalcon Mongodb Odm
MongoDB ODM for Phalcon framework for new mongodb php extension with query builder and rich functionality
Stars: ✭ 42 (+61.54%)
Mutual labels:  builder, query-builder
Ship Hold
data access framework for Postgresql on nodejs
Stars: ✭ 110 (+323.08%)
Mutual labels:  builder, query-builder
AdvancedSQL
The best Java query builder/SQL connector.
Stars: ✭ 23 (-11.54%)
Mutual labels:  builder, query-builder
searchable
Pattern-matching search and reusable queries in laravel.
Stars: ✭ 28 (+7.69%)
Mutual labels:  query-builder
hotbuild
a cross platform hot compilation tool for golang
Stars: ✭ 181 (+596.15%)
Mutual labels:  builder
plasmic
Visual page builder and web design tool for any website or web app tech stack
Stars: ✭ 1,475 (+5573.08%)
Mutual labels:  builder
dqlx
A DGraph Query Builder
Stars: ✭ 41 (+57.69%)
Mutual labels:  builder
gsql
GSQL is a structured query language code builder for golang.
Stars: ✭ 106 (+307.69%)
Mutual labels:  builder
FlowUpdater
The free and open source solution to update Minecraft.
Stars: ✭ 54 (+107.69%)
Mutual labels:  builder
claw
Source code of Claw Key logger previously sold on HackForums
Stars: ✭ 33 (+26.92%)
Mutual labels:  builder
uibuilder.nim
UI prototyping w/ Glade for lazy me
Stars: ✭ 21 (-19.23%)
Mutual labels:  builder
buildit.nvim
A better async project builder for Neovim
Stars: ✭ 18 (-30.77%)
Mutual labels:  builder
SilentXMRMiner
A Silent (Hidden) Monero (XMR) Miner Builder
Stars: ✭ 417 (+1503.85%)
Mutual labels:  builder
html2rss-web
🕸 Generates and delivers RSS feeds via HTTP. Create your own feeds or get started quickly with the included configs.
Stars: ✭ 36 (+38.46%)
Mutual labels:  builder
typesql
TypeSQL - Generate Typescript API from raw MySQL queries. Compatible with Deno and Node.
Stars: ✭ 37 (+42.31%)
Mutual labels:  query-builder
slim-routing
Slim framework powered-up routing
Stars: ✭ 14 (-46.15%)
Mutual labels:  builder

This project is under development, If you want, Let's Go!

Database

Introduction

Database SQL builder, written in Go, provides a convenient to creating and running database queries. Here is an api server example.

Configuration

The database configuration is located at database.yml. In this file you may define all of your database connections, as well as specify which connection should be used by default. Examples for most of the supported database systems are provided in this file.

default: mysql
sqlite:
   driver: sqlite3
   database: /absolute/path/to/gogogo.sqlite
   prefix:
mysql:
  driver: mysql
  host: localhost
  port: 3306
  database: gogogo
  username: root
  password:
  unix_socket:
  charset: utf8mb4
  collation: utf8mb4_unicode_ci
  prefix:
pgsql:
  driver: postgres
  host: 127.0.0.1
  port: 5432
  database: gogogo
  username: qclaogui
  password:
  charset: utf8
  prefix:
  sslmode: disable

Using Multiple Database Connections

When using multiple connections, you may access each connection via the connection method on the DM. The name passed to the connection method should correspond to one of the connections listed in your database.yml configuration file:

package main

import "github.com/qclaogui/database/builder"

DB, DM := builder.Run("/absolute/path/to/database.yml")

users :=DB.Table("users").Get()
// or
users = DM.Connection("pgsql").Table("users").Get()

Retrieving Results

Retrieving All Rows From A Table

You may use the Table method on the DB(Connector interface) to begin a query

DB, _ := builder.Run("/absolute/path/to/database.yml")

users := DB.Table("users").Get()

Retrieving A Single Row / Column From A Table

users := DB.Table("users").Limit(1).Get()

Value method will return the value of the column directly:

users := DB.Table("users").Where("name", "John").Value("email")

Aggregates

The query builder also provides a variety of aggregate methods such as count, max, min, avg, and sum. You may call any of these methods after constructing your query:

users := DB.Table("users").Count()

users := DB.Table("users").Max("id")

price := DB.Table("orders").Where("finalized", "1").Avg("price")

Selects

Specifying A Select Clause

Using the Select method, you can specify a custom Select clause for the query:

users :=DB.Table("users").Select("name", "email as user_email").Get()

The Distinct method allows you to force the query to return distinct results:

users :=DB.Table("users").Distinct().Get()

Where Clauses

Simple Where Clauses

In general, the Where method requires three arguments. The first argument is the name of the column. The second argument is an operator, which can be any of the database's supported operators. Finally, the third argument is the value to evaluate against the column.

users :=DB.Table("users").Where("votes", "=", "100").Get()
// or 
users :=DB.Table("users").Where("votes", "100").Get()

you may use a variety of other operators when writing a where clause:

users :=DB.Table("users").Where("votes",">=", "100").Get()

users :=DB.Table("users").Where("votes","<>", "100").Get()

users :=DB.Table("users").Where("votes","like", "T%").Get()

Or Statements

You may chain where constraints together as well as add or clauses to the query. The orWhere method accepts the same arguments as the where method:

users :=DB.Table("users").Where("votes",">", "100").OrWhere('name', 'John').Get()

whereBetween

The whereBetween method verifies:

users :=DB.Table("users").WhereBetween("created_at", "2017-01-08", "2018-03-06").Get()

whereBetween / WhereNotBetween

The whereBetween method verifies that a column's value is between two values:

users :=DB.Table("users").WhereBetween("votes", "1", "100").Get()

users :=DB.Table("users").WhereNotBetween("votes", "1", "100").Get()

WhereIn / whereNotIn

The WhereIn method verifies that a given column's value is contained within the given array:

users :=DB.Table("users").WhereIn("id", "1", "2","3").Get()
// or 
users :=DB.Table("users").WhereIn("id", []string{"1","2","3"}...).Get()

users :=DB.Table("users").WhereNotIn("id", "1", "2","3").Get()

users :=DB.Table("users").WhereNotIn("id", []string{"1","2","3"}...).Get()

WhereDate / WhereMonth / WhereDay / WhereYear / WhereTime The WhereDate method may be used to compare a column's value against a date:

users :=DB.Table("users").WhereDate("created_at", "2018-05-20").Get()

The WhereMonth method may be used to compare a column's value against a specific month of a year:

users :=DB.Table("users").WhereMonth("created_at", "12").Get()

The WhereDay method may be used to compare a column's value against a specific day of a month:

users :=DB.Table("users").WhereDay("created_at", "12").Get()

The WhereYear method may be used to compare a column's value against a specific year:

users :=DB.Table("users").WhereYear("created_at", "2018").Get()

The WhereTime method may be used to compare a column's value against a specific time:

users :=DB.Table("users").WhereTime("created_at","=", "12:30:15").Get()

Parameter Grouping

Sometimes, you might want to use parentheses to create a more advanced where statement, Only in this case ,The Where method requires four arguments. like:

users :=DB.Table("users").Where("age", ">=", "22", "(").Where("gender", "Male").Where("house", ">=", "1", ")").
		OrWhere("age", ">=", "20", "(").Where("gender", "=", "Female", ")").
		Get()

The example above will produce the following SQL(mysql):

select * from users where (age >= ? and gender = ? and house >= ?) or (age >= ? and gender = ?)

Ordering, Grouping, Limit, & Offset

OrderBy

The OrderBy method allows you to sort the result of the query by a given column. The first argument to the OrderBy method should be the column you wish to sort by, while the second argument controls the direction of the sort and may be either asc or desc:

users :=DB.Table("users").OrderBy("name", "desc").Get()

GroupBy / Having

The GroupBy and Having methods may be used to group the query results. The Having method's signature is similar to that of the Where method:

users :=DB.Table("users").GroupBy("account_id").Having("account_id", ">", "10").Get()

Skip / Take

To limit the number of results returned from the query, or to skip a given number of results in the query, you may use the Skip and Take methods:

users :=DB.Table("users").Skip(10).Take(5).Get()

Alternatively, you may use the limit and offset methods:

users :=DB.Table("users").Skip(10).Limit(5).Get()

Inserts

The query builder also provides an Insert method for inserting records into the database table.:

var usersData = []map[string]string{map[string]string{
			"name":  "gopher1",
			"email": "[email protected]",
		}, map[string]string{
			"name":  "gopher2",
			"email": "[email protected]",
		}}

users :=DB.Table("users").Insert(usersData)

Updates

Of course, the query builder can also update existing records using the Update method

var updateData =  map[string]string{
			"name":  "gopher2",
			"email": "[email protected]",
		}

users :=DB.Table("users").Update(updateData)

Deletes

The query builder may also be used to delete records from the table via the Delete method. You may constrain delete statements by adding Where clauses before calling the Delete method:

users :=DB.Table("users").Delete()

users :=DB.Table("users").Where('votes', '>', "100").Delete()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].