Test table
/*Navicat Premium Data Transfer source server:localhost Source Server type:postgresql Source server Vers ion:90401 source Host:localhost Source Database:mmc source Schema:public Target Server Typ E:postgresql Target Server version:90401 File encoding:utf-8 date:08/15/2015 20:24:56 PM*/-- ------------------------------Table structure for student-- ----------------------------DROP TABLE IF EXISTS" Public"." Student ";CREATE TABLE" Public"." Student "(" id "int4 not NULL DEFAULTNextval ('Student_id_seq':: Regclass), "name"varchar(255) not NULL DEFAULT "'::character varyingCOLLATE "default"," Age "Int4 not NULL DEFAULT 0) with(OIDS=FALSE);ALTER TABLE" Public"." Student "OWNER to"MMC";-- ------------------------------Records of Student-- ----------------------------BEGIN;INSERT into" Public"." StudentVALUES('1','Tom',' -');COMMIT;-- ------------------------------Primary key structure for table student-- ----------------------------ALTER TABLE" Public"." StudentADD PRIMARY KEY("id") notDeferrable initially IMMEDIATE;
Direct Sticker Code
Package Mainimport ("FMT" "Github.com/go-xorm/xorm" _ "GITHUB.COM/LIB/PQ" "reflect" "unsafe")varEngine *Xorm. Enginefunc bytestostring (b []byte)string{bh:= (*reflect. Sliceheader) (unsafe. Pointer (&b) SH:=reflect. Stringheader{bh. Data, BH. Len}return*(*string)(unsafe. Pointer (&sh))} Func Stringtobytes (Sstring) []byte{sh:= (*reflect. Stringheader) (unsafe. Pointer (&s)) BH:= Reflect. Sliceheader{sh. Data, Sh. Len0} return*(*[]byte)(unsafe. Pointer (&BH))} Func main () {engine, _= Xorm. Newengine ("Postgres","user=mmc password=mmc dbname=mmc host=127.0.0.1 port=5432 sslmode=disable") sql:="SELECT * FROM Student"Rowarray, _:=engine. Query (SQL) for_, Row: =Range Rowarray { forColName, Colvalue: =Range Row {value:=bytestostring (colvalue) fmt. Println (colname, Value) }}}
Examples of xorm using Pgsql