Merge pull request #100 from niiyz/dev-sequence

Add sequence.
This commit is contained in:
Dan Sosedoff 2015-11-16 21:19:57 -06:00
commit 4fb24cb229
9 changed files with 305 additions and 242 deletions

View File

@ -164,6 +164,11 @@ func GetConnectionInfo(c *gin.Context) {
c.JSON(200, res.Format()[0])
}
func GetSequences(c *gin.Context) {
res, err := DbClient.Sequences()
serveResult(res, err, c)
}
func GetActivity(c *gin.Context) {
res, err := DbClient.Activity()
serveResult(res, err, c)

View File

@ -25,6 +25,7 @@ func SetupRoutes(router *gin.Engine) {
api.POST("/connect", Connect)
api.GET("/databases", GetDatabases)
api.GET("/connection", GetConnectionInfo)
api.GET("/sequences", GetSequences)
api.GET("/activity", GetActivity)
api.GET("/schemas", GetSchemas)
api.GET("/tables", GetTables)

View File

@ -136,6 +136,10 @@ func (client *Client) TableIndexes(table string) (*Result, error) {
return res, err
}
func (client *Client) Sequences() ([]string, error) {
return client.fetchRows(statements.PG_SEQUENCES)
}
// Returns all active queriers on the server
func (client *Client) Activity() (*Result, error) {
return client.query(statements.PG_ACTIVITY)

View File

@ -188,6 +188,20 @@ func test_TableIndexes(t *testing.T) {
assert.Equal(t, 2, len(res.Rows))
}
func test_Sequences(t *testing.T) {
res, err := testClient.Sequences()
expected := []string{
"author_ids",
"book_ids",
"shipments_ship_id_seq",
"subject_ids",
}
assert.Equal(t, nil, err)
assert.Equal(t, expected, res)
}
func test_Query(t *testing.T) {
res, err := testClient.Query("SELECT * FROM books")
@ -257,6 +271,7 @@ func TestAll(t *testing.T) {
test_TableRows(t)
test_TableInfo(t)
test_TableIndexes(t)
test_Sequences(t)
test_Query(t)
test_QueryError(t)
test_QueryInvalidTable(t)

File diff suppressed because one or more lines are too long

View File

@ -31,6 +31,8 @@ WHERE table_name = $1`
PG_TABLES = `SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_schema,table_name`
PG_SEQUENCES = `SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = 'public' ORDER BY sequence_name`
PG_ACTIVITY = `SELECT
datname,
query,

View File

@ -125,7 +125,7 @@
color: #555;
}
#sidebar div.tables-list #tables {
#sidebar div.tables-list #tables, #sequences {
padding: 33px 0 0;
font-size: 12px;
}

View File

@ -38,6 +38,7 @@
<span class="refresh" id="refresh_tables" title="Refresh tables list"><i class="fa fa-refresh"></i></span>
</div>
<ul id="tables"></ul>
<ul id="sequences"></ul>
</div>
</div>
<div class="table-information">

View File

@ -23,6 +23,7 @@ function getTableStructure(table, cb) { apiCall("get", "/tables/" + table, {},
function getTableIndexes(table, cb) { apiCall("get", "/tables/" + table + "/indexes", {}, cb); }
function getHistory(cb) { apiCall("get", "/history", {}, cb); }
function getBookmarks(cb) { apiCall("get", "/bookmarks", {}, cb); }
function getSequences(cb) { apiCall("get", "/sequences", {}, cb); }
function encodeQuery(query) {
return window.btoa(query);
@ -46,6 +47,16 @@ function loadTables() {
});
}
function loadSequences() {
$("#sequences li").remove();
getSequences(function(data) {
data.forEach(function(item) {
$("<li><span><i class='fa fa-chevron-right'></i> " + item + " </span></li>").appendTo("#sequences");
});
});
}
function escapeHtml(str) {
if (str != null || str != undefined) {
return jQuery("<div/>").text(str).html();
@ -89,6 +100,7 @@ function performTableAction(table, action) {
executeQuery("DROP TABLE " + table, function(data) {
if (data.error) alert(data.error);
loadTables();
loadSequences();
resetTable();
});
break;
@ -312,6 +324,7 @@ function runQuery() {
// Refresh tables list if table was added or removed
if (query.match(re)) {
loadTables();
loadSequences();
}
});
}
@ -538,6 +551,7 @@ $(document).ready(function() {
$("#tables").on("click", "li", function() {
$("#tables li.selected").removeClass("selected");
$("#sequences li.selected").removeClass("selected");
$(this).addClass("selected");
$("#tables").attr("data-current", $.trim($(this).text()));
@ -555,8 +569,20 @@ $(document).ready(function() {
}
});
$("#sequences").on("click", "li", function() {
$("#tables li.selected").removeClass("selected");
$("#sequences li.selected").removeClass("selected");
$(this).addClass("selected");
$("#tables").attr("data-current", $.trim($(this).text()));
showTableContent();
$(".table-information ul").hide();
});
$("#refresh_tables").on("click", function() {
loadTables();
loadSequences();
});
$("#edit_connection").on("click", function() {
@ -655,6 +681,7 @@ $(document).ready(function() {
else {
connected = true;
loadTables();
loadSequences();
$("#connection_window").hide();
$("#current_database").text(resp.current_database);
@ -674,6 +701,7 @@ $(document).ready(function() {
else {
connected = true;
loadTables();
loadSequences();
$("#current_database").text(resp.current_database);
$("#main").show();