top
(README.md)
Serve-db aims to expose a db as web services
--------------------------------------------
注:这是一个练手的工具,用来学习go.

1. 在要连接的数据库中新增一张表, *serve_easy*
```sql
CREATE TABLE `serve_easy` (
  `uri` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `sql` varchar(1024) COLLATE utf8_unicode_ci DEFAULT NULL,
  `params` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
  `replacements` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
  `desc` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  PRIMARY KEY (`uri`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
```

2. 在新建的表中插入一些数据
```sql
INSERT INTO `serve_easy` (`uri`,`sql`,`params`,`replacements`,`desc`,`created`) VALUES ('descTable','desc {table}','','table','查看表字段',now());
INSERT INTO `serve_easy` (`uri`,`sql`,`params`,`replacements`,`desc`,`created`) VALUES ('listServices','select * from serve_easy order by created desc','',NULL,'获取给定id的用户',now());
INSERT INTO `serve_easy` (`uri`,`sql`,`params`,`replacements`,`desc`,`created`) VALUES ('getServiceByUri','select * from serve_easy where uri = ?','uri',NULL,'获取给定id的用户',now());
```

3. 到项目根目录下执行
```bash
go build
./serve-db -port=8080 -db_url="go:go@tcp(localhost:3306)/qn1"
```

4. 访问
  1. [http://localhost:8080/listServices](http://localhost:8080/listServices)
  2. [http://localhost:8080/descTable?table=serve_easy](http://localhost:8080/descTable?table=serve_easy)
  3. [http://localhost:8080/getServiceByUri?uri=listServices](http://localhost:8080/getServiceByUri?uri=listServices)

5. 如何添加新任务(见[example.html](example.html))

Imports 1 package(s)

  1. github.com/go-sql-driver/mysql