Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

SQL Where like filter expression for entql and gorm

License

Notifications You must be signed in to change notification settings

wenerme/go-miniquery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-miniquery

GoDoc Build Status Coverage Status Go Report Card

SQL Where like safe filter expression for entql and gorm

gorm

  • use reflect to get model graph
  • support join relation
package main

import "gorm.io/gorm"

func TestMiniQuery() {
	var db *gorm.DB
	// build to username = ? and Profile__age > ?
	db.Model(User{}).Scopes(ApplyMiniQuery(`username="wener" && Profile.age > 18`)).Rows()
}

entql

  • generate entsql - recommend
    • depends on generated graph - will validate when build
    • support edge filter
  • generate entql
    • function is not as complete as entsql
    • do not depends on generated graph - validate when entql to sql
package main

import "entgo.io/ent/dialect/sql"

func TestEntSQL() {
	var s *sql.Selector
	s.Where(sql.P(func(builder *sql.Builder) {
		b := &entmq.MiniQLToEntSQLBuilder{
			Node:        node,          // *sqlgraph.Node
			Graph:       schemaGraph,   // *sqlgraph.Schema
			QueryString: query,
		}
		builder.Join(b)
		err := b.Err()
		if err != nil {
			panic(errors.Wrap(err, "invalid query"))
		}
	}))
}

About

SQL Where like filter expression for entql and gorm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published