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
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 ¶
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 SqlIn ¶
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
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
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.