Git Product home page Git Product logo

go-orm-db's Introduction

go-orm-db

Test ORM using golang

Oracle

Wish to use ORM but no reference and libraries found.
And There is NO WAY to use Oracle DB in MAC M1. -> Installed it to AWS Ubuntu 20.04.

Posted on my blog : Handling oracle database using golang

MariaDB

Docker

  1. Get Docker image
$ docker pull mariadb
# If you want another verion (10.3)
$ docker pull mariadb:10.3
  1. Start container
$ docker run --name testdbcontainer -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -d mariadb
# If you want to run another version (10.3)
$ docker run --name testdbcontainer -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -d mariadb:10.3
  1. Execute
$ docker exec -it testdbcontainer mysql -u root -p 

go.mod

# GORM
$ go get -u github.com/jinzhu/gorm
# MySQL driver for GORM
$ go get github.com/go-sql-driver/mysql

Create database and user with grant

> create database bcstatus;
> create user 'user'@'%' identified by 'userpw';
> select host,user from mysql.user;
> grant all privileges on bcstatus.* to 'user'@'localhost';
> rename user 'user'@'localhost' to 'user'@'%';

Create Table

> 
// CREATE TABLE statuses(  
//     id INT NOT NULL AUTO_INCREMENT,  
//     tx_id VARCHAR(100) NOT NULL,  
//     code VARCHAR(40) NOT NULL,      
//     PRIMARY KEY ( id )
// );

Log

Set global query for tracking queries only generated from mysql.

# Inside MariaDB
# -> docker exec -it testdbcontainer mysql -u root -p 

MariaDB [(none)]> SET GLOBAL general_log = 1;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SELECT @@log_output, @@general_log, @@general_log_file;
+--------------+---------------+--------------------+
| @@log_output | @@general_log | @@general_log_file |
+--------------+---------------+--------------------+
| FILE         |             1 | mach-W650EH.log    |
+--------------+---------------+--------------------+
1 row in set (0.00 sec)
MariaDB [(none)]>

References

go-orm-db's People

Contributors

wnjoon avatar

Watchers

 avatar  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.