Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

WinterYukky/with

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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`)

About

With support for GORM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published