sqlcommenter

package module
v0.0.0-...-7d368e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

GORM SQLCommenter Plugin

This plugin adds a new clause on GORM statement builder, allowing you to add tags to your requests using the SQLCommenter protocol.

How to use

package main

import (
  "gorm.io/gorm"
  "gorm.io/driver/sqlite"
  // Add plugin package
  sqlCommenter "github.com/gouyelliot/gorm-sqlcommenter-plugin"
)

func main() {
    db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
    if err != nil {
        panic("failed to connect database")
    }

    // Register the plugin in GORM
    db.Use(sqlCommenter.New())

    // Add SQLCommenter tag to your request
    db.Clauses(sqlCommenter.NewTag("application", "api")).Table("test").Scan(nil)
}

Documentation

Index

Constants

View Source
const GormClauseName = "plugin:sql-commenter"

Variables

This section is empty.

Functions

This section is empty.

Types

type SqlComment

type SqlComment struct {
	Tags map[string]string
}

SqlComment contains tags for the request

func NewTag

func NewTag(key string, value string) SqlComment

func NewTags

func NewTags(tags map[string]string) SqlComment

func (SqlComment) AddTag

func (sqlComment SqlComment) AddTag(key string, value string)

func (SqlComment) Build

func (sqlComment SqlComment) Build(builder clause.Builder)

Build builds the comment clause

func (SqlComment) MergeClause

func (sqlComment SqlComment) MergeClause(mergeClause *clause.Clause)

MergeClause merge SqlCommenter clauses

func (SqlComment) Name

func (sqlComment SqlComment) Name() string

type SqlCommenterPlugin

type SqlCommenterPlugin struct{}

func New

func New() *SqlCommenterPlugin

New create a new SqlCommenterPlugin

func (*SqlCommenterPlugin) Initialize

func (e *SqlCommenterPlugin) Initialize(db *gorm.DB) error

Initialize register BuildClauses used to generate the comment

func (*SqlCommenterPlugin) Name

func (e *SqlCommenterPlugin) Name() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL