Git Product home page Git Product logo

Comments (3)

afumu avatar afumu commented on September 20, 2024

image

	db := gormDb.Scopes(func(db *gorm.DB) *gorm.DB {
		// 自定义表
		return db.Table("users")
	})
	query, _ := gplus.NewQuery[User]()
	// 传入Db
	list, db := gplus.SelectList[User](query, gplus.Db(db))
	if db.Error != nil {
		return
	}
	for _, item := range list {
		fmt.Println(item)
	}

这样是否能满足你的要求

场景如下:通过租户或者ID首位分表(如user_1、user_2、user_3等),这种场景下只有前端的请求到来的时候,才知道应该具体去查询哪一张表,我在代码里没有看到关于表名的设置,目前我用的是GORM原生的Scopes方法去动态加载表名,可以为这个需求添加支持吗?

from gorm-plus.

PhoenixL0911 avatar PhoenixL0911 commented on September 20, 2024

image

	db := gormDb.Scopes(func(db *gorm.DB) *gorm.DB {
		// 自定义表
		return db.Table("users")
	})
	query, _ := gplus.NewQuery[User]()
	// 传入Db
	list, db := gplus.SelectList[User](query, gplus.Db(db))
	if db.Error != nil {
		return
	}
	for _, item := range list {
		fmt.Println(item)
	}

这样是否能满足你的要求

场景如下:通过租户或者ID首位分表(如user_1、user_2、user_3等),这种场景下只有前端的请求到来的时候,才知道应该具体去查询哪一张表,我在代码里没有看到关于表名的设置,目前我用的是GORM原生的Scopes方法去动态加载表名,可以为这个需求添加支持吗?

我目前就是这样子做的,但是这一部分的逻辑代码太多重复了。另外还有个,能否再添加一组QueryCond,类似mybatis plus的 boolean condition 那样,根据bool条件去决定是否要拼接sql。

from gorm-plus.

afumu avatar afumu commented on September 20, 2024

可以的,你感兴趣的话,也可以提交pr

from gorm-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.