Support MySQL or MariaDB for gopsql/psql and gopsql/db

Related tags

Database tools mysql
Overview

mysql

Support MySQL or MariaDB for github.com/gopsql/psql.

You can make MySQL SELECT, INSERT, UPDATE, DELETE statements with this package.

NOTE: Please don't use those features that are only available in PostgreSQL but not MySQL at the moment.

Example

$1", 1).Limit(10).MustQuery(&users) fmt.Println(users) } var ( models []*psql.Model ) func newModel(o interface{}) *psql.Model { m := psql.NewModel(o) models = append(models, m) return m } type timestamp time.Time func (t timestamp) String() string { return time.Time(t).Format(time.RFC3339) } func (t *timestamp) Scan(value interface{}) error { if v, ok := value.([]byte); ok { ts, err := strconv.ParseInt(string(v), 10, 64) if err != nil { return err } *t = timestamp(time.Unix(ts, 0)) } return nil } func (t timestamp) Value() (driver.Value, error) { return strconv.FormatInt(time.Time(t).Unix(), 10), nil } func (t timestamp) MarshalJSON() ([]byte, error) { return json.Marshal(time.Time(t)) } func (t *timestamp) UnmarshalJSON(b []byte) error { var m time.Time if err := json.Unmarshal(b, &m); err != nil { return err } *t = timestamp(m) return nil } ">
package main

import (
	"database/sql/driver"
	"encoding/json"
	"fmt"
	"strconv"
	"time"

	"github.com/gopsql/logger"
	"github.com/gopsql/mysql"
	"github.com/gopsql/psql"
)

type (
	User struct {
		// using a different table name other than "users"
		__TABLE_NAME__ string "user"

		Id        int
		Name      string
		Avatar    string
		Phone     *string   // can be null
		CreatedAt timestamp // use integer to store time
		UpdatedAt timestamp
	}
)

var (
	Users = newModel(User{})
)

func main() {
	conn := mysql.MustOpen("[email protected](127.0.0.1:33333)/yourdb")
	for _, m := range models {
		m.SetConnection(conn)
		m.SetLogger(logger.StandardLogger)
	}

	var users []User
	Users.Find().Where("id > $1", 1).Limit(10).MustQuery(&users)
	fmt.Println(users)
}

var (
	models []*psql.Model
)

func newModel(o interface{}) *psql.Model {
	m := psql.NewModel(o)
	models = append(models, m)
	return m
}

type timestamp time.Time

func (t timestamp) String() string {
	return time.Time(t).Format(time.RFC3339)
}

func (t *timestamp) Scan(value interface{}) error {
	if v, ok := value.([]byte); ok {
		ts, err := strconv.ParseInt(string(v), 10, 64)
		if err != nil {
			return err
		}
		*t = timestamp(time.Unix(ts, 0))
	}
	return nil
}

func (t timestamp) Value() (driver.Value, error) {
	return strconv.FormatInt(time.Time(t).Unix(), 10), nil
}

func (t timestamp) MarshalJSON() ([]byte, error) {
	return json.Marshal(time.Time(t))
}

func (t *timestamp) UnmarshalJSON(b []byte) error {
	var m time.Time
	if err := json.Unmarshal(b, &m); err != nil {
		return err
	}
	*t = timestamp(m)
	return nil
}
BQB is a lightweight and easy to use query builder that works with sqlite, mysql, mariadb, postgres, and others.

Basic Query Builder Why Simple, lightweight, and fast Supports any and all syntax by the nature of how it works Doesn't require learning special synta

Aaron M 37 Jun 11, 2022
mysql to mysql 轻量级多线程的库表数据同步

goMysqlSync golang mysql to mysql 轻量级多线程库表级数据同步 测试运行 设置当前binlog位置并且开始运行 go run main.go -position mysql-bin.000001 1 1619431429 查询当前binlog位置,参数n为秒数,查询结

null 13 Jun 14, 2022
MySQL Storage engine conversion,Support mutual conversion between MyISAM and InnoDB engines.

econvert MySQL Storage engine conversion 简介 此工具用于MySQL存储引擎转换,支持CTAS和ALTER两种模式,目前只支持MyISAM和InnoDB存储引擎相互转换,其它引擎尚不支持。 注意:当对表进行引擎转换时,建议业务停止访问或者极少量访问时进行。 原

null 5 Oct 25, 2021
go mysql driver, support distributed transaction

Go-MySQL-Driver A MySQL-Driver for Go's database/sql package Features Requirements Installation Usage DSN (Data Source Name) Password Protocol Address

Open Transaction 33 Apr 3, 2022
A Go rest API project that is following solid and common principles and is connected to local MySQL database.

This is an intermediate-level go project that running with a project structure optimized RESTful API service in Go. API's of that project is designed based on solid and common principles and connected to the local MySQL database.

Kıvanç Aydoğmuş 21 Jun 6, 2022
MySQL replication topology management and HA

orchestrator [Documentation] orchestrator is a MySQL high availability and replication management tool, runs as a service and provides command line ac

null 4.6k Jun 28, 2022
Interactive client for PostgreSQL and MySQL

dblab Interactive client for PostgreSQL and MySQL. Overview dblab is a fast and lightweight interactive terminal based UI application for PostgreSQL a

Daniel Omar Vergara Pérez 197 Jun 30, 2022
Interactive terminal user interface and CLI for database connections. MySQL, PostgreSQL. More to come.

?? dbui dbui is the terminal user interface and CLI for database connections. It provides features like, Connect to multiple data sources and instance

Kanan Rahimov 91 Jun 30, 2022
Devcloud-go provides a sql-driver for mysql which named devspore driver and a redis client which named devspore client,

Devcloud-go Devcloud-go provides a sql-driver for mysql which named devspore driver and a redis client which named devspore client, you can use them w

HUAWEI CLOUD 11 Jun 9, 2022
CRUD API example is written in Go using net/http package and MySQL database.

GoCrudBook CRUD API example is written in Go using net/http package and MySQL database. Requirements Go MySQL Code Editor Project Structure GoCrudBook

Serhat Karabulut 3 May 15, 2022
A proxy is database proxy that de-identifies PII for PostgresDB and MySQL

Surf Surf is a database proxy that is capable of de-identifying PII and anonymizing sentive data fields. Supported databases include Postgres, MySQL,

null 1 Dec 14, 2021
Mogo: a lightweight browser-based logs analytics and logs search platform for some datasource(ClickHouse, MySQL, etc.)

mogo Mogo is a lightweight browser-based logs analytics and logs search platform

Shimo HQ 687 Jul 4, 2022
Go-fiber - Implement CRUD Data Go and Mysql using Authentication & Authorization

Implement CRUD Data Go and Mysql using Authentication & Authorization

Stevra Silvanus 4 Jun 8, 2022
a powerful mysql toolset with Go

go-mysql A pure go library to handle MySQL network protocol and replication. Call for Committer/Maintainer Sorry that I have no enough time to maintai

siddontang 3.7k Jun 24, 2022
Sync MySQL data into elasticsearch

go-mysql-elasticsearch is a service syncing your MySQL data into Elasticsearch automatically. It uses mysqldump to fetch the origin data at first, the

siddontang 3.8k Jun 25, 2022
A high-performance MySQL proxy

kingshard 中文主页 Overview kingshard is a high-performance proxy for MySQL powered by Go. Just like other mysql proxies, you can use it to split the read

Fei Chen 6k Jun 28, 2022
Golang MySql binary log replication listener

Go MySql binary log replication listener Pure Go Implementation of MySQL replication protocol. This allow you to receive event like insert, update, de

Pavel <Ven> Gulbin 185 Apr 13, 2022
Vitess is a database clustering system for horizontal scaling of MySQL.

Vitess Vitess is a database clustering system for horizontal scaling of MySQL through generalized sharding. By encapsulating shard-routing logic, Vite

Vitess 14.3k Jul 6, 2022