Coder Social home page Coder Social logo

go_pgsql_orm's Introduction

go_pgsql_orm

summary

this is a simple example of go-pgsql-orm usage. i designed this simple lib to help myself learn go and postgresql better.

there are many improvements that can be done to this lib.

with this small lib you can:

  • connect to postgresql (singleton connection)
  • create schema (migrate)
  • create table (migrate)
  • insert data
  • read one record
  • alert table to change type of cols (migrate)
  • alert table to add new col (migrate)

this is a simple example of go-pgsql-orm usage.:

how to create schema:

package main

import (
	"fmt"
	"time"
	managers "github.com/aliaqa256/go_pgsql_orm/managerspkg"
)

type User struct {

	Id uint  `orm:"serial PRIMARY KEY"`
	CreatedAt time.Time 
	UpdatedAt time.Time 
	UserName string `orm:"varchar(255) not null"`
	Email string `orm:"varchar(255) not null"`
	Phone string `orm:"varchar(255) not null"`
	Age  float32  `orm:"int"`
}


func main() {
    a:= User{}
    modelpkg.Migrate(a)
}

how to insert data:

import (
	"fmt"
	"time"
	managers "github.com/aliaqa256/go_pgsql_orm/managerspkg"
)
func main() {
    user := &User{
        UserName: "Aliaqa",
        Email: "[email protected]"
        age: 25,
        Phone: "09121234567",
    }
    managers.Create(user)
}

how to get id of one record:

dbc:=managers.GetId(user,map[string]string{
 	"username": "aliaqa",
    "email": "[email protected]"
 })

 fmt.Println(dbc.Resualt)

how to get < filed > of one record:

                    ///   struct,id,fieldname
	dbc:=managers.GetField(user,26,"age")
	fmt.Println(dbc.Resualt)

if you have any suggestions or questions please contact me at :

https://alilotfidev.ir
[email protected]

go_pgsql_orm's People

Contributors

aliaqa256 avatar

Stargazers

Saeed Madadi avatar koxuan avatar Zoha Behnam avatar Kerolos Wahba avatar soheil avatar Raha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.