Skip to content

Commit 37f8bb3

Browse files
committed
Update README
Signed-off-by: Manuel Carmona <manu.carmona90@gmail.com>
1 parent eaecf4a commit 37f8bb3

File tree

1 file changed

+79
-6
lines changed

1 file changed

+79
-6
lines changed

README.md

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,91 @@ We are continuously adding more functionality to go-mysql-server. We support a s
2727

2828
| | Supported |
2929
|:----------------------:|:---------------------------------------------------------------------------------:|
30-
| Comparison expressions | !=, ==, >, <, >=,<=, BETWEEN |
31-
| Null check expressions | IS NULL, IS NOT NULL |
32-
| Grouping expressions | COUNT, MIN, MAX ,AVG |
33-
| Standard expressions | ALIAS, LITERAL, STAR (*) |
34-
| Statements | CROSS JOIN, INNER JOIN, DESCRIBE, FILTER (WHERE), GROUP BY, LIMIT, SELECT, SHOW TABLES, SORT, DISTINCT |
35-
| Functions | SUBSTRING |
30+
| Comparison expressions | !=, ==, >, <, >=,<=, BETWEEN, REGEXP, IN, NOT IN |
31+
| Null check expressions | IS NULL, IS NOT NULL |
32+
| Grouping expressions | COUNT, MIN, MAX ,AVG |
33+
| Standard expressions | ALIAS, LITERAL, STAR (*) |
34+
| Statements | CROSS JOIN, INNER JOIN, DESCRIBE, FILTER (WHERE), GROUP BY, LIMIT/OFFSET, SELECT, SHOW TABLES, SORT, DISTINCT, CREATE TABLE, INSERT |
35+
| Functions | SUBSTRING, ARRAY_LENGTH |
3636
| Time functions | YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, DAYOFYEAR |
3737

3838
## Custom functions
3939

4040
- `IS_BINARY(blob)`: returns whether a BLOB is a binary file or not
4141

42+
## Example
43+
44+
`go-mysql-server` has a sql engine and a server implementation, so to start a server you must instantiate the engine and give it your `sql.Database` implementation that will be in charge to handle all the logic about retrieving the data from your source :
45+
46+
```go
47+
...
48+
driver := sqle.New()
49+
driver.AddDatabase(createTestDatabase())
50+
51+
auth := mysql.NewAuthServerStatic()
52+
auth.Entries["user"] = []*mysql.AuthServerStaticEntry{{
53+
Password: "pass",
54+
}}
55+
56+
config := server.Config{
57+
Protocol: "tcp",
58+
Address: "localhost:5432",
59+
Auth: auth,
60+
}
61+
62+
s, err := server.NewDefaultServer(config, driver)
63+
if err != nil {
64+
panic(err)
65+
}
66+
67+
s.Start()
68+
...
69+
```
70+
71+
Then, you can connect to the server with any mysql client:
72+
```bash
73+
> mysql --host=127.0.0.1 --port=5123 -u user -ppass db -e "SELECT * FROM mytable"
74+
+----------+-------------------+-------------------------------+---------------------+
75+
| name | email | phone_numbers | created_at |
76+
+----------+-------------------+-------------------------------+---------------------+
77+
| John Doe | john@doe.com | ["555-555-555"] | 2018-04-18 10:42:58 |
78+
| John Doe | johnalt@doe.com | [] | 2018-04-18 10:42:58 |
79+
| Jane Doe | jane@doe.com | [] | 2018-04-18 10:42:58 |
80+
| Evil Bob | evilbob@gmail.com | ["555-666-555","666-666-666"] | 2018-04-18 10:42:58 |
81+
+----------+-------------------+-------------------------------+---------------------+
82+
```
83+
84+
See the complete example [here](_example/main.go).
85+
86+
### Queries examples
87+
88+
```
89+
SELECT count(name) FROM mytable
90+
+---------------------+
91+
| COUNT(mytable.name) |
92+
+---------------------+
93+
| 4 |
94+
+---------------------+
95+
96+
SELECT name,year(created_at) FROM mytable
97+
+----------+--------------------------+
98+
| name | YEAR(mytable.created_at) |
99+
+----------+--------------------------+
100+
| John Doe | 2018 |
101+
| John Doe | 2018 |
102+
| Jane Doe | 2018 |
103+
| Evil Bob | 2018 |
104+
+----------+--------------------------+
105+
106+
SELECT email FROM mytable WHERE name = 'Evil Bob'
107+
+-------------------+
108+
| email |
109+
+-------------------+
110+
| evilbob@gmail.com |
111+
+-------------------+
112+
```
113+
114+
42115
## Powered by go-mysql-server
43116

44117
* [gitquery](https://github.com/src-d/gitquery)

0 commit comments

Comments
 (0)