psql

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Dialect dialect
)

Functions

This section is empty.

Types

type DeleteMod

type DeleteMod = sq.QueryMod[tag.DeleteTag]

type DeleteModApply

type DeleteModApply = sq.QueryModApply[tag.DeleteTag]

type DeleteQuery

type DeleteQuery = sq.Query[tag.DeleteTag]

func Delete

func Delete(mods ...DeleteMod) DeleteQuery

type InsertMod

type InsertMod = sq.QueryMod[tag.InsertTag]

type InsertModApply

type InsertModApply = sq.QueryModApply[tag.InsertTag]

type InsertQuery

type InsertQuery = sq.Query[tag.InsertTag]

func Insert

func Insert(mods ...InsertMod) InsertQuery

type SelectMod

type SelectMod = sq.QueryMod[tag.SelectTag]

type SelectModApply

type SelectModApply = sq.QueryModApply[tag.SelectTag]

type SelectQuery

type SelectQuery = sq.Query[tag.SelectTag]

func Select

func Select(mods ...SelectMod) SelectQuery
Example (LiteralSimple)
package main

import (
	"fmt"

	"github.com/rrgmc/litsql/dialect/psql"
	"github.com/rrgmc/litsql/dialect/psql/sm"
)

func main() {
	// SELECT
	q := psql.Select(
		// u.id, u.name
		sm.Columns("u.id", "u.name"),
		// , u.created_at, u.updated_at
		sm.Columns("u.created_at", "u.updated_at"),
		// FROM users As u
		sm.From("users AS u"),
		// WHERE u.age > 40
		sm.Where("u.age > 40"),
		// AND u.deleted_at IS NOT NULL
		sm.Where("u.deleted_at IS NOT NULL"),
		// ORDER BY u.name ASC, u.age DESC
		sm.OrderBy("u.name ASC", "u.age DESC"),
	)
	qs, _, err := q.Build()
	if err != nil {
		panic(err)
	}
	fmt.Println(qs)

}
Output:

SELECT u.id, u.name, u.created_at, u.updated_at
FROM users AS u
WHERE u.age > 40 AND u.deleted_at IS NOT NULL
ORDER BY u.name ASC, u.age DESC
Example (LiteralSimpleInvalid)
package main

import (
	"fmt"

	"github.com/rrgmc/litsql/dialect/psql"
	"github.com/rrgmc/litsql/dialect/psql/sm"
)

func main() {
	// the library won't prevent invalid SQL from being generated, like when using raw string.

	// SELECT
	q := psql.Select(
		// u.id, u.name of user
		sm.Columns("u.id", "u.name of user"),
		// FROM users AND NOT users
		sm.From("users AND NOT users"),
		// WHERE CREATE TABLE users
		sm.Where("CREATE TABLE users"),
	)
	qs, _, err := q.Build()
	if err != nil {
		panic(err)
	}
	fmt.Println(qs)

}
Output:

SELECT u.id, u.name of user
FROM users AND NOT users
WHERE CREATE TABLE users

type UpdateMod

type UpdateMod = sq.QueryMod[tag.UpdateTag]

type UpdateModApply

type UpdateModApply = sq.QueryModApply[tag.UpdateTag]

type UpdateQuery

type UpdateQuery = sq.Query[tag.UpdateTag]

func Update

func Update(mods ...UpdateMod) UpdateQuery

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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