stevenzack / px

PostgreSQL driver extention (ORM)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PGX

Simple PostgreSQL ORM extension for Golang

Install

go get -u github.com/StevenZack/px

Example

package main

import (
	"database/sql"
	"fmt"
	"log"
	"time"

	"github.com/StevenZack/px"
)

type User struct {
	Id          uint32                                               // serial not null primary key
	PhoneNumber sql.NullString    `limit:"36" index:"unique"` // varchar(36) unique index
	Info        map[string]string                                  // jsonb
	UpdateTime  time.Time         `index:""`
	CreateTime  time.Time         
}

func init() {
	log.SetFlags(log.Lshortfile)
}

func main() {

	urlExample := "postgres://stevenzack:@localhost:5432/langenius"
	c, e := px.NewBaseModel(urlExample, User{})
	if e != nil {
		log.Println(e)
		return
	}
	id, e := c.Insert(User{
		PhoneNumber: sql.NullString{Valid: true, String: "asd"},
	})
	if e != nil {
		log.Println(e)
		return
	}
	fmt.Println("inserted: ", id)

	v, e := c.Find(id)
	if e != nil {
		log.Println(e)
		return
	}
	fmt.Println(v)
}

About

PostgreSQL driver extention (ORM)

License:MIT License


Languages

Language:Go 100.0%