with

package module
v0.0.0-...-c8642c4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 2 Imported by: 0

README

with

GO

⚠️This repository is deprecated. Please see extra-clause-plugin project

With support for GORM

Use a With clause

import "github.com/WinterYukky/with"

with := with.New(db).
    Append("`apple_buyers` AS (SELECT `user_id` FROM `sales` WHERE product = ?)", "apple").
    Append("`orange_buyers` AS (?)", db.Model(&Sale{}).Select("user_id").Where("product = ?", "orange"))
db.Clauses(with).
    Where("users.id IN (?)", db.Table("apple_buyers")).
    Where("users.id IN (SELECT * FROM `orange_buyers`)")).Find(&User{})

// WITH 
//   `apple_buyers` AS (SELECT `user_id` FROM `sales` WHERE product = 'apple'),
//   `orange_buyers` AS (SELECT `user_id` FROM `sales` WHERE product = 'orange')
// SELECT * FROM `users` WHERE users.id IN (SELECT * FROM `apple_buyers`) AND users.id IN (SELECT * FROM `orange_buyers`)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type With

type With struct {
	// contains filtered or unexported fields
}

With is a with clause.

.ex

DB.Clauses(New(DB).Append("`buyers` AS (SELECT `user_id` FROM `sales`)")).Where("users.id IN (SELECT * FROM buyers)").Find(&User{})

Make this query.

WITH `buyers` AS (SELECT user_id FROM `sales`) SELECT * FROM `users` WHERE users.id IN (SELECT * FROM `buyers`)

func New

func New(tx *gorm.DB) With

New create a with clause.

func (With) Append

func (with With) Append(query string, args ...interface{}) With

Append a with clause.

func (With) Build

func (with With) Build(builder clause.Builder)

Build implements gorm interface

func (With) ModifyStatement

func (with With) ModifyStatement(stmt *gorm.Statement)

ModifyStatement implements gorm interface

Jump to

Keyboard shortcuts

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