misc

package
v2.7.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Funciones misceláneas

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddInterval added in v2.2.0

func AddInterval(t pgtype.Timestamp, i pgtype.Interval) (result pgtype.Timestamp)

Añade un pgtype.Interval a un pgtype.Timestamp

Example
package main

import (
	"fmt"

	"github.com/horus-es/go-util/v2/errores"
	"github.com/horus-es/go-util/v2/formato"
	"github.com/horus-es/go-util/v2/misc"
	"github.com/jackc/pgx/v5/pgtype"
)

func main() {
	unDia := pgtype.Interval{Days: 1, Valid: true}
	fechaInicial, err := formato.ParseTimestamp("4/7/2023 12:00", formato.DMA)
	errores.PanicIfError(err)
	fechaSiguiente := misc.AddInterval(fechaInicial, unDia)
	fmt.Println(formato.PrintTimestamp(fechaSiguiente, formato.DMA))
}
Output:

05/07/2023 12:00

func EscapeSQL

func EscapeSQL(s string) string

Escapa un texto para su uso en órdenes SQL

Example
package main

import (
	"fmt"

	"github.com/horus-es/go-util/v2/misc"
)

func main() {
	sql := `select * from tabla where nombre=` + misc.EscapeSQL("O'Brian")
	fmt.Println(sql)
}
Output:

select * from tabla where nombre='O''Brian'

func GetGID added in v2.4.0

func GetGID() int64

Obtiene el ID de la goroutine actual

func SqlIn

func SqlIn(valores ...string) string

Compone parte de una clausula WHERE CAMPO IN (VALORES...) Devuelve "in (VALORES...)" o "= VALOR" o "is null"

Example
package main

import (
	"fmt"

	"github.com/horus-es/go-util/v2/misc"
)

func main() {
	codigos := []string{"cero", "uno", "dos", "tres"}
	sql := `select * from tabla where codigo` + misc.SqlIn(codigos[1:]...)
	fmt.Println(sql)
}
Output:

select * from tabla where codigo in ('uno','dos','tres')

func SubInterval added in v2.2.0

func SubInterval(t pgtype.Timestamp, i pgtype.Interval) (result pgtype.Timestamp)

Sustrae un pgtype.Interval de un pgtype.Timestamp

Example
package main

import (
	"fmt"

	"github.com/horus-es/go-util/v2/errores"
	"github.com/horus-es/go-util/v2/formato"
	"github.com/horus-es/go-util/v2/misc"
	"github.com/jackc/pgx/v5/pgtype"
)

func main() {
	unDia := pgtype.Interval{Days: 1, Valid: true}
	fechaInicial, err := formato.ParseTimestamp("4/7/2023 12:00", formato.DMA)
	errores.PanicIfError(err)
	fechaAnterior := misc.SubInterval(fechaInicial, unDia)
	fmt.Println(formato.PrintTimestamp(fechaAnterior, formato.DMA))
}
Output:

03/07/2023 12:00

func Title

func Title(s string) string

Hace lo mismo que la deprecada strings.Title: pasar la primera letra a mayúsculas

Example
package main

import (
	"fmt"

	"github.com/horus-es/go-util/v2/misc"
)

func main() {
	fmt.Println(misc.Title("hola mundo otra vEZ"))
}
Output:

Hola Mundo Otra VEZ

Types

This section is empty.

Jump to

Keyboard shortcuts

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