-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from k1LoW/mariadb-version-detect
Support MariaDB
- Loading branch information
Showing
27 changed files
with
2,078 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package mariadb | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/k1LoW/tbls/drivers" | ||
"github.com/k1LoW/tbls/drivers/mysql" | ||
) | ||
|
||
type Mariadb struct { | ||
mysql.Mysql | ||
} | ||
|
||
// New return new Mariadb | ||
func New(db *sql.DB, opts ...drivers.Option) (*Mariadb, error) { | ||
m, err := mysql.New(db, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
m.EnableMariaMode() | ||
return &Mariadb{*m}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package mariadb | ||
|
||
import ( | ||
"database/sql" | ||
"os" | ||
"testing" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/k1LoW/tbls/schema" | ||
"github.com/xo/dburl" | ||
) | ||
|
||
var s *schema.Schema | ||
var db *sql.DB | ||
|
||
func TestMain(m *testing.M) { | ||
s = &schema.Schema{ | ||
Name: "testdb", | ||
} | ||
db, _ = dburl.Open("maria://root:mypass@localhost:33309/testdb") | ||
defer db.Close() | ||
exit := m.Run() | ||
if exit != 0 { | ||
os.Exit(exit) | ||
} | ||
} | ||
|
||
func TestAnalyzeView(t *testing.T) { | ||
driver, err := New(db) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = driver.Analyze(s) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
view, _ := s.FindTableByName("post_comments") | ||
if got := view.Def; got == "" { | ||
t.Errorf("got not empty string.") | ||
} | ||
} | ||
|
||
func TestExtraDef(t *testing.T) { | ||
driver, err := New(db) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := driver.Analyze(s); err != nil { | ||
t.Fatal(err) | ||
} | ||
tbl, _ := s.FindTableByName("comments") | ||
{ | ||
c, _ := tbl.FindColumnByName("id") | ||
got := c.ExtraDef | ||
if want := "auto_increment"; got != want { | ||
t.Errorf("got %v\nwant %v", got, want) | ||
} | ||
} | ||
{ | ||
c, _ := tbl.FindColumnByName("post_id_desc") | ||
got := c.ExtraDef | ||
if want := "GENERATED ALWAYS AS `post_id` * -1 VIRTUAL"; got != want { | ||
t.Errorf("got %v\nwant %v", got, want) | ||
} | ||
} | ||
} | ||
|
||
func TestInfo(t *testing.T) { | ||
driver, err := New(db) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
d, err := driver.Info() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if d.Name != "mariadb" { | ||
t.Errorf("got %v\nwant %v", d.Name, "mariadb") | ||
} | ||
if d.DatabaseVersion == "" { | ||
t.Errorf("got not empty string.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# CamelizeTable | ||
|
||
## Description | ||
|
||
<details> | ||
<summary><strong>Table Definition</strong></summary> | ||
|
||
```sql | ||
CREATE TABLE `CamelizeTable` ( | ||
`id` bigint(20) NOT NULL AUTO_INCREMENT, | ||
`created` datetime NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 | ||
``` | ||
|
||
</details> | ||
|
||
## Columns | ||
|
||
| Name | Type | Default | Nullable | Extra Definition | Children | Parents | Comment | | ||
| ---- | ---- | ------- | -------- | --------------- | -------- | ------- | ------- | | ||
| id | bigint(20) | | false | auto_increment | | | | | ||
| created | datetime | | false | | | | | | ||
|
||
## Constraints | ||
|
||
| Name | Type | Definition | | ||
| ---- | ---- | ---------- | | ||
| PRIMARY | PRIMARY KEY | PRIMARY KEY (id) | | ||
|
||
## Indexes | ||
|
||
| Name | Definition | | ||
| ---- | ---------- | | ||
| PRIMARY | PRIMARY KEY (id) USING BTREE | | ||
|
||
## Relations | ||
|
||
 | ||
|
||
--- | ||
|
||
> Generated by [tbls](https://github.com/k1LoW/tbls) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# testdb | ||
|
||
## Description | ||
|
||
Sample database document. | ||
|
||
## Labels | ||
|
||
`sample` `tbls` | ||
|
||
## Tables | ||
|
||
| Name | Columns | Comment | Type | | ||
| ---- | ------- | ------- | ---- | | ||
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE | | ||
| [comments](comments.md) | 7 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE | | ||
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE | | ||
| [hyphen-table](hyphen-table.md) | 3 | | BASE TABLE | | ||
| [logs](logs.md) | 7 | Auditログ | BASE TABLE | | ||
| [posts](posts.md) | 7 | Posts table | BASE TABLE | | ||
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW | | ||
| [users](users.md) | 6 | Users table | BASE TABLE | | ||
| [user_options](user_options.md) | 4 | User options table | BASE TABLE | | ||
|
||
## Relations | ||
|
||
 | ||
|
||
--- | ||
|
||
> Generated by [tbls](https://github.com/k1LoW/tbls) |
Oops, something went wrong.