Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Package builder receives user input and generates an AST using "stmt" package. | ||
// | ||
// There is four builder to manipulate an AST: Select, Insert, Update and Delete. | ||
// | ||
// When the AST is ready, you can use String(), NamedQuery() or Query() to generate the underlying query. | ||
// However, be vigilant with String(): it's mainly used for debugging because it's completely vulnerable | ||
// to SQL injection... | ||
package builder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Package loukoum provides a simple SQL Query Builder. | ||
// At the moment, only PostgreSQL is supported. | ||
// | ||
// If you have to generate complex queries, which rely on various contexts, loukoum is the right tool for you. | ||
// It helps you generate SQL queries from composable parts. | ||
// However, keep in mind it's not an ORM or a Mapper so you have to use a SQL connector | ||
// (like "database/sql" or "sqlx", for example) to execute queries. | ||
// | ||
// If you're afraid to slip a tiny SQL injection manipulating fmt (or a byte buffer...) when you append | ||
// conditions, loukoum is here to protect you against yourself. | ||
// | ||
// For further informations, you can read this documentation: | ||
// https://github.com/ulule/loukoum/blob/master/README.md | ||
// | ||
// Or you can discover loukoum with these examples. | ||
// An "insert" can be generated like that: | ||
// | ||
// builder := loukoum.Insert("comments"). | ||
// Set( | ||
// loukoum.Pair("email", comment.Email), | ||
// loukoum.Pair("status", "waiting"), | ||
// loukoum.Pair("message", comment.Message), | ||
// loukoum.Pair("created_at", loukoum.Raw("NOW()")), | ||
// ). | ||
// Returning("id") | ||
// | ||
// Also, if you need an upsert, you can define a "on conflict" clause: | ||
// | ||
// builder := loukoum.Insert("comments"). | ||
// Set( | ||
// loukoum.Pair("email", comment.Email), | ||
// loukoum.Pair("status", "waiting"), | ||
// loukoum.Pair("message", comment.Message), | ||
// loukoum.Pair("created_at", loukoum.Raw("NOW()")), | ||
// ). | ||
// OnConflict("email", loukoum.DoUpdate( | ||
// loukoum.Pair("message", comment.Message), | ||
// loukoum.Pair("status", "waiting"), | ||
// loukoum.Pair("created_at", loukoum.Raw("NOW()")), | ||
// loukoum.Pair("deleted_at", nil), | ||
// )). | ||
// Returning("id") | ||
// | ||
// Updating a news is also simple: | ||
// | ||
// builder := loukoum.Update("news"). | ||
// Set( | ||
// loukoum.Pair("published_at", loukoum.Raw("NOW()")), | ||
// loukoum.Pair("status", "published"), | ||
// ). | ||
// Where(loukoum.Condition("id").Equal(news.ID)). | ||
// And(loukoum.Condition("deleted_at").IsNull(true)). | ||
// Returning("published_at") | ||
// | ||
// You can remove a specific user: | ||
// | ||
// builder := loukoum.Delete("users"). | ||
// Where(loukoum.Condition("id").Equal(user.ID)) | ||
// | ||
// Or select a list of users... | ||
// | ||
// builder := loukoum.Select("id", "first_name", "last_name", "email"). | ||
// From("users"). | ||
// Where(loukoum.Condition("deleted_at").IsNull(true)) | ||
// | ||
package loukoum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package format escape various types for types.RawContext. | ||
package format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Package stmt defines various statements and clauses that are used to generate queries. | ||
// | ||
// Unless you have to develop complex queries, you should'nt have to use this package. | ||
package stmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Package types defines some internal types that are handled by the "builder" and "stmt" package. | ||
// | ||
// RawContext, StdContext and NamedContext are used to generate queries. | ||
package types |