lucasres / goquent Goto Github PK
View Code? Open in Web Editor NEWa query build with SQL style sintex
a query build with SQL style sintex
We want a delete clause
method should be given the name of the table to be deleted
sintaxe of code will like this:
q, args, _ := goquent.New(goquent.MYSQL).Delete("table").Where(&goquent.C{"id", "=", 1}).Build()
// DELETE FROM users WHERE id = ?
this object of lib is create a query builder sql with sintax most near of sql real sintax. Now we have a select instruction and need a from
instruction for that we make a select base command
select * from table
Can create a signature for From method
From(t string) {
...
}
We need a unit test for select instruction
We have a some reserved words in sql that probabily have same name of columns in real database. Like for example key.
So we need add ` in name of column when ToSQL()
was called.
We need something like `key` and not key
The lib should be can handle with insert instruction
The insert method shoul be like:
func Insert() *QueryBuilder
func Into(t string, c ...string) &QueryBuilder
func Values(values ...V)
goquent.New().Insert().Into("table", "col1", "col2", "col3").Values(&goquent.V{"a","b", "c"}, &goquent.V{"a","b", "c"})
Is very comum that devs handle create conditional logic with more that one value like this (... AND ... AND ...)
. So we need a similar function in lib
We have a goquent.P{}
that is a slice of goquent.C{}
and that conditional is grouped with (... AND ...)
example in code:
Where(
goquent.P{
goquent.C{"status", "=", "actived", "OR"},
goquent.C{"name", "LIKE", "%actived%"},
},
goquent.C{"email", "LIKE", "%@email.com%"},
)
this need generate this sql
WHERE (status = ? OR name LIKE ?) AND email = ?
dont forgive of args
We need a group by and like a sql
can method signature like this:
GroupBy(cols ...string)
Method can recived columns
The method of update should be like:
Update(table string)
Set(sets ...*goquent.S)
Set method will should create a SET clause and recevi a S
struct, this struct should like C
. The first args is a column name and the second args is a value to set
Not matter the that you make if dont have a good documentation nobody will use it. SO we want a documentation for use this lib
Need a create a where test for success and fail cases.
We need a where clause for where sql.
The method signature can be like this:
Where(col string, op OperationType, val interface{})
The OperationType is a like enum with And, Or, In, Between
Depending on the SGBD we have a different way of building SQL, it's very important that lib can handle different SGBD for now we can handle mysql and add more later
the dialect must be set in constructor method
q := goquent.New(goquent.MYSQL)
We need a github action for run test when pr is make to main
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.