@@ -27,18 +27,91 @@ We are continuously adding more functionality to go-mysql-server. We support a s
27
27
28
28
| | Supported |
29
29
| :----------------------:| :---------------------------------------------------------------------------------:|
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 |
36
36
| Time functions | YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, DAYOFYEAR |
37
37
38
38
## Custom functions
39
39
40
40
- ` IS_BINARY(blob) ` : returns whether a BLOB is a binary file or not
41
41
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
+
42
115
## Powered by go-mysql-server
43
116
44
117
* [ gitquery] ( https://github.com/src-d/gitquery )
0 commit comments