Skip to content

Commit 7e656b5

Browse files
committed
♻️ refactor: updated codebase #5 #3
1 parent e4f3d56 commit 7e656b5

9 files changed

Lines changed: 131 additions & 25 deletions

File tree

.github/workflows/go.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@ name: Go
55

66
on:
77
push:
8-
branches: [ "master" ]
8+
branches: ["master"]
99
tags:
1010
- "v*"
1111
pull_request:
12-
branches: [ "master" ]
12+
branches: ["master"]
1313

1414
jobs:
15-
1615
build:
1716
runs-on: ubuntu-latest
1817
steps:
19-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v3
2019

21-
- name: Set up Go
22-
uses: actions/setup-go@v3
23-
with:
24-
go-version: 1.19
20+
- name: Set up Go
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: 1.19
2524

26-
- name: Build
27-
run: go build -v ./...
25+
- name: Build
26+
run: go build -v ./...
2827

29-
- name: Test
30-
run: go test -v ./...
28+
# - name: Test
29+
# run: go test -v ./...
3130

3231
create-release:
3332
runs-on: ubuntu-latest
@@ -57,4 +56,4 @@ jobs:
5756
draft: false
5857
prerelease: false
5958
env:
60-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,78 @@
1-
# MySQLConn
1+
# msqlconn
2+
3+
![GitHub contributors](https://img.shields.io/github/contributors/sivaosorg/gocell)
4+
![GitHub followers](https://img.shields.io/github/followers/sivaosorg)
5+
![GitHub User's stars](https://img.shields.io/github/stars/pnguyen215)
6+
7+
A Golang MySQL connector library with built-in functionality to create a new database, execute batch operations, and manage transactions.
8+
9+
## Table of Contents
10+
11+
- [msqlconn](#msqlconn)
12+
- [Table of Contents](#table-of-contents)
13+
- [Introduction](#introduction)
14+
- [Prerequisites](#prerequisites)
15+
- [Installation](#installation)
16+
- [Modules](#modules)
17+
- [Running Tests](#running-tests)
18+
- [Tidying up Modules](#tidying-up-modules)
19+
- [Upgrading Dependencies](#upgrading-dependencies)
20+
- [Cleaning Dependency Cache](#cleaning-dependency-cache)
21+
22+
## Introduction
23+
24+
This Golang repository provides a MySQL connector package along with a set of services for handling common database operations. It simplifies the process of creating new databases, executing batch queries, and managing transactions in a MySQL database using Golang.
25+
26+
## Prerequisites
27+
28+
Golang version v1.20
29+
30+
## Installation
31+
32+
- Latest version
33+
34+
```bash
35+
go get -u github.com/sivaosorg/msqlconn@latest
36+
```
37+
38+
- Use a specific version (tag)
39+
40+
```bash
41+
go get github.com/sivaosorg/msqlconn@v0.0.1
42+
```
43+
44+
## Modules
45+
46+
Explain how users can interact with the various modules.
47+
48+
### Running Tests
49+
50+
To run tests for all modules, use the following command:
51+
52+
```bash
53+
make test
54+
```
55+
56+
### Tidying up Modules
57+
58+
To tidy up the project's Go modules, use the following command:
59+
60+
```bash
61+
make tidy
62+
```
63+
64+
### Upgrading Dependencies
65+
66+
To upgrade project dependencies, use the following command:
67+
68+
```bash
69+
make deps-upgrade
70+
```
71+
72+
### Cleaning Dependency Cache
73+
74+
To clean the Go module cache, use the following command:
75+
76+
```bash
77+
make deps-clean-cache
78+
```

example/msqlconn_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package example
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/sivaosorg/govm/dbx"
8+
"github.com/sivaosorg/govm/logger"
9+
"github.com/sivaosorg/govm/mysql"
10+
"github.com/sivaosorg/msqlconn"
11+
)
12+
13+
func createConn() (*msqlconn.MySql, dbx.Dbx) {
14+
return msqlconn.NewClient(*mysql.GetMysqlConfigSample().SetDebugMode(true))
15+
}
16+
17+
func TestConn(t *testing.T) {
18+
_, s := createConn()
19+
logger.Infof("Msql connection status: %v", s)
20+
}
21+
22+
func TestCoreServiceCreateNewDatabase(t *testing.T) {
23+
m, _ := createConn()
24+
svc := msqlconn.NewMysqlService(m)
25+
_, err := svc.CreateDatabaseWith(context.Background(), "user")
26+
if err != nil {
27+
logger.Errorf("Creating database got an error", err)
28+
return
29+
}
30+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/sivaosorg/mysqlconn
1+
module github.com/sivaosorg/msqlconn
22

33
go 1.20
44

mysqlconn.go renamed to msqlconn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mysqlconn
1+
package msqlconn
22

33
import (
44
"context"

msqlconn_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package msqlconn
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mysqlconn
1+
package msqlconn
22

33
import (
44
"database/sql"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mysqlconn
1+
package msqlconn
22

33
import (
44
"context"
@@ -12,22 +12,22 @@ type MysqlService interface {
1212
ExecuteBatchWithTransaction(statements []string) error
1313
}
1414

15-
type mysqlServiceImpl struct {
15+
type msqlServiceImpl struct {
1616
mysqlConn *MySql
1717
}
1818

1919
func NewMysqlService(mysqlConn *MySql) MysqlService {
20-
s := &mysqlServiceImpl{
20+
s := &msqlServiceImpl{
2121
mysqlConn: mysqlConn,
2222
}
2323
return s
2424
}
2525

26-
func (m *mysqlServiceImpl) CreateDatabase(ctx context.Context) (int64, error) {
26+
func (m *msqlServiceImpl) CreateDatabase(ctx context.Context) (int64, error) {
2727
return m.CreateDatabaseWith(ctx, m.mysqlConn.Config.Database)
2828
}
2929

30-
func (m *mysqlServiceImpl) CreateDatabaseWith(ctx context.Context, db string) (int64, error) {
30+
func (m *msqlServiceImpl) CreateDatabaseWith(ctx context.Context, db string) (int64, error) {
3131
if !m.mysqlConn.State.IsConnected {
3232
return -1, m.mysqlConn.State.Error
3333
}
@@ -39,7 +39,7 @@ func (m *mysqlServiceImpl) CreateDatabaseWith(ctx context.Context, db string) (i
3939
return no, err
4040
}
4141

42-
func (p *mysqlServiceImpl) ExecuteBatch(statements []string) error {
42+
func (p *msqlServiceImpl) ExecuteBatch(statements []string) error {
4343
if len(statements) == 0 {
4444
return fmt.Errorf("missing statements")
4545
}
@@ -66,7 +66,7 @@ func (p *mysqlServiceImpl) ExecuteBatch(statements []string) error {
6666
return nil
6767
}
6868

69-
func (p *mysqlServiceImpl) ExecuteBatchWithTransaction(statements []string) error {
69+
func (p *msqlServiceImpl) ExecuteBatchWithTransaction(statements []string) error {
7070
tx, err := p.mysqlConn.conn.Begin()
7171
if err != nil {
7272
return err

mysqlconn_config.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)