programming

List Foreign key constrants defined in a database

June 21, 2020
sql, programming, database

tags Programming Code snippets Postgres Postgres View foreign key constrants defined in all databases select kcu.table_schema || '.' ||kcu.table_name as foreign_table, '>-' as rel, rel_tco.table_schema || '.' || rel_tco.table_name as primary_table, string_agg(kcu.column_name, ', ') as fk_columns, kcu.constraint_name from information_schema.table_constraints tco join information_schema.key_column_usage kcu on tco.constraint_schema = kcu.constraint_schema and tco.constraint_name = kcu.constraint_name join information_schema.referential_constraints rco on tco.constraint_schema = rco.constraint_schema and tco.constraint_name = rco.constraint_name join information_schema.table_constraints rel_tco on rco.unique_constraint_schema = rel_tco. ...

Go reading struct tag

June 21, 2020
go, programming

tags Go Programming Programming Code snippets The following code reads a specific struct Tag by name. import ( "reflect" "strings" "fmt" ) type Profile struct { Id int `validate:"numeric" json:"id"` First string `validate:"required" json:"first"` Last string `validate:"required" json:"last"` Birth string `validate:"required" json:"birth"` Sex string `validate:"required" json:"sex"` MaritalStatus string `validate:"required" json:"marital_status"` Children int `validate:"numeric" json:"children"` } func GetStructFieldValidators(data interface{}) map[string][]string { v := reflect.ValueOf(data) t := reflect.TypeOf(data) validators := make(map[string][]string) for i := 0; i < v. ...

Go defer

June 19, 2020
go, programming, cs

tags Go Programming Programming import "fmt" func trace(name string) string { fmt.Println("Entering ", name) return name } func un(name string) string { fmt.Println("Exiting", name) return name } func a() { defer un(trace("a")) fmt.Println("Hello, world") } func b(){ defer un(trace("b")) fmt.Println("Before i < 10 loop") for i:=0 ; i < 10; i++{ defer fmt.Println("i =", i) } fmt.Println("After i < 10 loop") } func main(){ a() b() } Entering a Hello, world Exiting a Entering b Before i < 10 loop After i < 10 loop i = 9 i = 8 i = 7 i = 6 i = 5 i = 4 i = 3 i = 2 i = 1 i = 0 Exiting b

C programming

May 31, 2020
C, programming

Tags Computer Science Programming C project architecture guidelines # Functions exposed in the header are like public methods # Think of each module like a class. The functions you expose in the header are like public methods. Only put a function in the header if it part of the module’s needed interface. Avoiding circular module dependencies # Avoid circular module dependencies. Module A and module B should not call each other. ...

Go Programming

May 31, 2020
go, programming

tags Programming Computer Science Related notes: Interesting Golang libraries Packages # In Go, programs start running in package main. Package names are defined by the last element of the import path: import math/rand has files which begin with the package rand. Packages consists of a bunch of .go files. Package identifiers (functions, variables, struct and other data), may be used in other packages, with a few exceptions. Go allows only exported identifiers to be called after the package import. ...

Interesting Golang libraries

May 30, 2020
go, programming

https://github.com/jmoiron/sqlx https://pg.uptrace.dev/guide/ https://github.com/go-pg/pg Entered on [2020-05-27 Wed 21:36] <~/workspace/commit-validator/requirements.txt>

The Go Programming Language Specification - The Go Programming Language

go, programming

tags Go Programming Programming For an operand x of type T, the address operation &x generates a pointer of type *T to x. The operand must be addressable, that is, either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array indexing operation of an addressable array. As an exception to the addressability requirement, x may also be a (possibly parenthesized) composite literal. ...