xorm使用pgsql的例子
测试表
/*
Navicat Premium Data Transfer Source Server : localhost
Source Server Type : PostgreSQL
Source Server Version : 90401
Source Host : localhost
Source Database : mmc
Source Schema : public Target Server Type : 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 DEFAULT nextval('student_id_seq'::regclass),
"name" varchar(255) NOT NULL DEFAULT ''::character varying COLLATE "default",
"age" int4 NOT NULL DEFAULT 0
)
WITH (OIDS=FALSE);
ALTER TABLE "public"."student" OWNER TO "mmc"; -- ----------------------------
-- Records of student
-- ----------------------------
BEGIN;
INSERT INTO "public"."student" VALUES ('', 'tom', '');
COMMIT; -- ----------------------------
-- Primary key structure for table student
-- ----------------------------
ALTER TABLE "public"."student" ADD PRIMARY KEY ("id") NOT DEFERRABLE INITIALLY IMMEDIATE;
直接贴代码
package main import (
"fmt"
"github.com/go-xorm/xorm"
_ "github.com/lib/pq"
"reflect"
"unsafe"
) var engine *xorm.Engine func BytesToString(b []byte) string {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := reflect.StringHeader{bh.Data, bh.Len}
return *(*string)(unsafe.Pointer(&sh))
} func StringToBytes(s string) []byte {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh := reflect.SliceHeader{sh.Data, sh.Len, }
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 {
for colName, colValue := range row {
value := BytesToString(colValue)
fmt.Println(colName, value)
}
}
}
xorm使用pgsql的例子的更多相关文章
- PL/pgSQL的RETURN QUERY例子
我的例子: 数据准备: create table custinfo(custid integer,callingcnt integer); ,),(,),(,); 函数生成: CREATE OR RE ...
- PL/pgSQL的 RETURN NEXT例子
从网上找到例子: 可以说,RETURN NEXT要用在循环中: 例子一: 数据准备: CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT); ...
- PL/pgSQL的anyelement例子
http://www.postgresonline.com/journal/archives/239-The-wonders-of-Any-Element.html 定义函数 pgsql=# CREA ...
- PL/pgSQL RETURNS TABLE 例子
实验如下: RETURNS TABLE 中的变量名和SQL文中的变量名同名时,执行时会出错: pgsql=# create table sales(itemno integer,quantity in ...
- PL/pgSQL多输出参数例子
例子一,不带returns: postgres=# CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS ...
- PL/pgSQL函数带output参数例子
例子1,不带returns : [postgres@cnrd56 bin]$ ./psql psql () Type "help" for help. postgres=# CRE ...
- PL/pgSQL学习笔记之七
http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 如果一个PL/pgSQL函数声明了输出参数,输出参数被赋予$n名 ...
- PL/pgSQL学习笔记之五
http://www.postgresql.org/docs/9.1/static/plpgsql-declarations.html 39.3. 声明 块中使用的所有的变量必须在块的声明节中进行声明 ...
- 2015第42周六Pgsql全文索引
全文搜索通常也就是文本搜索,它可以提供满足查询的识别自然语言的能力,并且任意性地通过相关性查询进行排序.搜索最常见的类型就是找到所有包含给定的查询术语的记录,并且以相似性的查询顺序返回它们. 对于普通 ...
随机推荐
- Sql 2000丢失sa 密码,重置sa密码
重置密码需要勾选一个授权 在企业管理器中-->服务器设置——>勾选“运行对系统目录直接进行修改” 勾选后就可以重置密码了. /////////////////// 详细: http://w ...
- centos网页乱码
修改vi /etc/my.cnf [client] (新增)default-character-set=utf8 [mysql] (添加)default-character-set=utf8
- Notes of Linked Data concept and application - TODO
Motivation [反正债多了不愁,再开个方向.] Data plays a core role in most business systems, data storage and retrie ...
- CSS控制文本超出指定宽度后用省略号代替,CSS控制文本不换行
CSS控制文本超出指定宽度后用省略号代替,CSS控制文本不换行. 一般的文字截断(适用于内联与块): .text-overflow { display:block;/*内联对象需加*/ ...
- leetcode 135. Candy ----- java
There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...
- JavaWeb学习记录(二十)——Model1模式(javaBean+jsp)实现简单计算器案例
¨JSP技术提供了三个关于JavaBean组件的动作元素,即JSP标签,它们分别为: ¨<jsp:useBean>标签:用于在JSP页面中查找或实例化一个JavaBean组件. ¨< ...
- poj1511 最短路
题意:与poj3268一样,所有人需要从各点到一点再从一点到各点,求最短路总和. 与poj3268一样,先正向建图跑 dijkstra ,得到该点到其他所有各点的最短路,即这些人回去的最短路,再用反向 ...
- poj3660 最短路/拓扑序
题意:有n头牛,为了给牛排顺序,给出了牛之间的胜负关系,具有传递性,问给出的胜负关系是否可以给这些牛排出唯一的顺序. 其实是个拓扑排序问题,牛的胜负关系就是有向边,然后判断是否有唯一的拓扑序就行.当然 ...
- jQuery 鼠标滚轮插件应用 mousewheel
jQuery Mousewheel Plugin,用于添加跨浏览器的鼠标滚轮支持. mousewheel事件的处理函数有一点小小的变化,它除了第一个参数event 外,还接收到第二个参数delta. ...
- 论文笔记之:RATM: RECURRENT ATTENTIVE TRACKING MODEL
RATM: RECURRENT ATTENTIVE TRACKING MODEL ICLR 2016 本文主要内容是 结合 RNN 和 attention model 用来做目标跟踪. 其中模型的组成 ...