Examples of xorm using Pgsql

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.