simple and useful gorm's plugin

gorm-plugin


ExplainPlugin


Check if index is used when thresholdTime <= sqlCostTime

import (
    "github.com/longlihale/gorm-plugin"
)

DB.Use(gormplugin.NewExplainPluginWithTimeout(3 * time.Millisecond))

// create users
DB.Create(createUsers)

DB.Model(&User{}).Where("name = ?", "user_1").Find(&User{})
// [error] sql:[SELECT * FROM `users` WHERE name = 'user_1' AND `users`.`deleted_at` IS NULL], not hit index.

DB.Model(&User{}).Where("age = ?", 1).Find(&User{})
// [info] sql:[SELECT * FROM `users` WHERE age = 1 AND `users`.`deleted_at` IS NULL], hit index: [idx_users_age].

NOTE: only support MySQL and not recommended for online.


UnderwritePlugin

Read again master when master-slave data is inconsistent when rows = 0 && err == nil

import (
    "github.com/longlihale/gorm-plugin"
)

DB.Use(gormplugin.NewUnderwritePlugin())

DB.Clauses(dbresolver.Write).Create(&User{Name: "kinggo", Age: 18})
// INSERT INTO `users` (`created_at`,`updated_at`,`deleted_at`,`name`,`age`) VALUES ('2021-12-22 14:47:23.776','2021-12-22 14:47:23.776',NULL,'kinggo',18)

conn := DB.Clauses(dbresolver.Read).Where("Age = ?", 18).Find(&User{})
//exec sql:[SELECT * FROM `users` WHERE Age = 18 AND `users`.`deleted_at` IS NULL] in master db

if conn.RowsAffected != 1 {
    t.Fatalf("underwrite failed.")
}

NOTE

  • it is suitable for GET, not for Query.
  • should new another *gorm.DB to use it.
Similar Resources

Forms814 - A website builder, useful for writing data collection webapps quickly.

Forms814 - A website builder, useful for writing data collection webapps quickly.

forms814 A website builder, useful for writing data collection webapps quickly. Project Design The method in use here is to mix it with complicated fo

Oct 25, 2022

Go-http-sleep: Delayed response http server, useful for testing various timeout issue for application running behind proxy

delayed response http server, useful for testing various timeout issue for application running behind proxy

Jan 22, 2022

Useful collection functions for golang, based on generic types

go-collection English | 简体中文 go-collection provides developers with a convenient set of functions for working with common slices, maps, and arrays dat

Jul 21, 2022

Powered by Matterbridge, MatterAMXX is a plugin for AMXX that allows simple bridging between your game servers, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, and more.

Powered by Matterbridge, MatterAMXX is a plugin for AMXX that allows simple bridging between your game servers, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, and more.

Powered by Matterbridge, MatterAMXX is a plugin for AMXX that allows simple bridging between your game servers, Mattermost, IRC, XMPP, Gitter, Slack, Discord, Telegram, and more.

Dec 27, 2022

Header Block is a middleware plugin for Traefik to block request and response headers which regex matched by their name and/or value

Header Block is a middleware plugin for Traefik to block request and response headers which regex matched by their name and/or value Conf

May 24, 2022

🤖 Automatically scrape PortableApps.com (or official release page) and convert into Edgeless plugin package

Edgeless 自动插件机器人 2 简介 该项目是为了使用 Golang 重新实现 Edgeless 自动插件机器人 特性 (WIP) 完全兼容 Edgeless 自动插件机器人,包括 Tasks,以实现无缝迁移 更快的构建速度 更好的代码结构 更高的拓展性 工作进度 截止至 2021/11/28

Sep 12, 2022

Traefik proxy plugin to extract HTTP header value and create a new header with extracted value

Copy header value Traefik plugin Traefik plugin that copies HTTP header value with format key1=value1; key2=value2 into a new header. Motivation for t

May 26, 2022

A Tor package updater and runner as an I2P Plugin

A Tor package updater and runner as an I2P Plugin

i2p.plugins.tor-updater A Tor package updater and runner as an I2P Plugin. This plugin is still being changed rapidly but it should be usable on most

Jul 31, 2022

A Go library for connecting to HandlerSocket (github.com/ahiguti/HandlerSocket-Plugin-for-MySQL)

handlersocket-go Go library for connecting to HandlerSocket Mysql plugin. See github.com/ahiguti/HandlerSocket-Plugin-for-MySQL/ Installation $ go get

Jan 19, 2021
Related tags
Feb 10, 2022
Cf-cli-find-app-plugin - CF CLI plugin to find applications containing a search string

Overview This cf cli plugin allows users to search for application names that co

Jan 3, 2022
Twitter-plugin - Falco Plugin for Twitter Stream

Twitter Plugin This repository contains the twittter plugin for Falco, which fol

Mar 17, 2022
llb - It's a very simple but quick backend for proxy servers. Can be useful for fast redirection to predefined domain with zero memory allocation and fast response.

llb What the f--k it is? It's a very simple but quick backend for proxy servers. You can setup redirect to your main domain or just show HTTP/1.1 404

Sep 27, 2022
GBPool-- a simple but useful golang free proxy pool

GBPool-- a simple but useful golang free proxy pool Intro(English) (中文) GBPool, golang baipiao proxy pool, a free & simple golang proxy pool module, g

May 30, 2022
A quick and dirty but useful tool to download each text/html page from the wayback machine for a specific domain and search for keywords within the saved content

wayback-keyword-search A quick and dirty but useful tool to download each text/html page from the wayback machine for a specific domain and search for

Dec 2, 2022
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.

Fast passive subdomain enumeration tool. Features • Install • Usage • API Setup • License • Join Discord Subfinder is a subdomain discovery tool that

Jan 4, 2023
Multiplexer over TCP. Useful if target server only allows you to create limited tcp connections concurrently.

tcp-multiplexer Use it in front of target server and let your client programs connect it, if target server only allows you to create limited tcp conne

May 27, 2021
golang useful http client

gequest 简体中文 | English 一个轻量级的、语义化的、链式操作的 golang http 客户端封装 用法 要求: golang >= 1.14 安装 go get -u "github.com/smallcatx0/gequest" import ( request "g

Sep 18, 2021
Collection of useful golang code snippets, mainly for learning purposes

Go-Things Collection of go code snippets, tools, etc. mainly for learning purpos

Dec 31, 2021