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全文索引
全文搜索通常也就是文本搜索,它可以提供满足查询的识别自然语言的能力,并且任意性地通过相关性查询进行排序.搜索最常见的类型就是找到所有包含给定的查询术语的记录,并且以相似性的查询顺序返回它们. 对于普通 ...
随机推荐
- jqueryIFrame框架内元素操作
//获取框架内元素 $(document.getElementById('main').contentWindow.document.body).find("#txtRD_Num" ...
- MySQL数据库恢复的经历。
蛋疼,定时任务设置错误.把数据给删除了.还有一次是服务器时间不对,也把数据给删除了. 还好,开启了二进制日志,才算把数据找回,但是速度效率也太低. 痛定思变.在把一切交由电脑工作的时候,也要做好一定的 ...
- Linux磁盘文件的命名
磁盘的常用接口有两种:IDE和SATA接口,目前主流的是SATA接口. IDE接口由IDE扁平电缆线连接,一个电缆可连接两个IDE接口,通常主机又都会提供两个IDE接口,因此最多可以接到四个IDE设备 ...
- 143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...
- bzoj 1012 维护一个单调数列
Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...
- JS初学之-选项卡(常见)
思路:鼠标滑过的效果直接用a:hover实现的,比较简便,缺点是在IE下不兼容. 为每一个Li添加点击事件,将每一个li用自定义属性的方法与div相匹配,重点是在点击事件内,要先遍历每一个div, ...
- JS初学之-if else图片顺序及循环切换
初学JS,代码还需多多改进,自学中... <!doctype html><html><head><meta charset="utf-8" ...
- html5表单新特性
type=range 值区域范围 默认值(0-100) type=data 选择日期 type=color value='初始值' 颜色选择器控件 type=search 搜索框效果 type=im ...
- Android—进度条
layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
- java jfinal + ajaxfileupload.js 上传
功能上传 需求:同时上传多张图片 前端:jquery.ajaxfileupload.js 后端:jfinal upload.htm <html> <body> <div ...