gf icon indicating copy to clipboard operation
gf copied to clipboard

improve logging printing in ORM sql

Open oldme-git opened this issue 1 year ago • 3 comments

resolved #2098 resolved #2241

old: QQ截图20240213012936

new: QQ截图20240213012830

oldme-git avatar Feb 12 '24 17:02 oldme-git

test code:


func TestA(t *testing.T) {
	db.SetDebug(true)

	var (
		num = 5
		wg  = sync.WaitGroup{}
	)
	wg.Add(num)

	for i := 0; i < num; i++ {
		go func(i int) {
			defer wg.Done()
			sql := fmt.Sprintf("select sleep(%d)", i)
			db.Raw(sql).All()
		}(i)
	}
	wg.Wait()
}

oldme-git avatar Feb 12 '24 17:02 oldme-git

这个日志就会出现2次打印了,有这折中的方案吗?

houseme avatar Feb 19 '24 03:02 houseme

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


This log will be printed twice. Is there a compromise?

Issues-translate-bot avatar Feb 19 '24 03:02 Issues-translate-bot

@houseme 暂时还没有想到,讨论一下

oldme-git avatar Feb 23 '24 10:02 oldme-git

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@houseme I haven’t thought of it yet, let’s discuss it

Issues-translate-bot avatar Feb 23 '24 10:02 Issues-translate-bot

@oldme-git @houseme 这两个issue的诉求是想要有一定的手段观测正在执行中的sql语句,不一定是要打印两条sql语句日志,这种方式有点丑,目前还没见到哪种语言的ORM会打印两条sql语句来满足这个诉求。我之前考虑过增加执行sql记录的方式,并提供查询当前正在执行sql的管理方法来满足。但这个诉求优先级并不高,所以一直没去做。

gqcn avatar Feb 27 '24 11:02 gqcn

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@oldme-git @houseme The appeal of these two issues' is to have a certain method to observe the sqlstatements being executed, not necessarily to print twosqlstatement logs. This method is a bit ugly. I haven't seen any language'sORMthat prints twosqlstatements to satisfy this request. I have previously considered adding a way to executesqlrecords and providing a management method to query the currently executingsql` to satisfy this need. But the priority of this request is not high, so it has never been done.

Issues-translate-bot avatar Feb 27 '24 11:02 Issues-translate-bot