-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ab39f89
Showing
19 changed files
with
2,006 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"directory": "data" | ||
} |
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,3 @@ | ||
*.so | ||
install.rdf | ||
*.h |
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,66 @@ | ||
(function() { | ||
|
||
var self = require("sdk/self"); | ||
|
||
var Chrome = require("chrome"); | ||
var ctypes = Chrome.Cu.import("resource://gre/modules/ctypes.jsm", null).ctypes; | ||
var Servicves = Chrome.Cu.import("resource://gre/modules/Services.jsm"); | ||
var ResProtocolHandler = Services.io.getProtocolHandler("resource") | ||
.QueryInterface(Chrome.Ci.nsIResProtocolHandler); | ||
var ChromeRegistry = Chrome.Cc["@mozilla.org/chrome/chrome-registry;1"] | ||
.getService(Chrome.Ci.nsIChromeRegistry); | ||
|
||
var resolveToFile = function(uri) { | ||
switch (uri.scheme) { | ||
case "chrome": | ||
return resolveToFile(ChromeRegistry.convertChromeURL(uri)); | ||
case "resource": | ||
return resolveToFile(Services.io.newURI(ResProtocolHandler.resolveURI(uri), null, null)); | ||
case "file": | ||
return uri.QueryInterface(Chrome.Ci.nsIFileURL).file; | ||
default: | ||
throw new Error("Cannot resolve"); | ||
} | ||
} | ||
|
||
var GoString = new ctypes.StructType("GoString", [ | ||
{ "p": ctypes.char.ptr }, | ||
{ "n": ctypes.int } | ||
]); | ||
|
||
var makeGoString = function(str) { | ||
var gs = new GoString(); | ||
gs.p = ctypes.char.array()(str); | ||
gs.n = str.length; | ||
return gs; | ||
}; | ||
|
||
var SelectQueryResult = new ctypes.StructType("SelectQuery_return", [ | ||
{ "r0": GoString }, { "r1": GoString } | ||
]); | ||
|
||
var lib = ctypes.open( | ||
resolveToFile(Services.io.newURI(self.data.url("./go/firefox-mysql.so"), null, null)).path | ||
); | ||
|
||
var connect = lib.declare("Connect", ctypes.default_abi, GoString, GoString); | ||
var disconnect = lib.declare("Disconnect", ctypes.default_abi, GoString); | ||
var selectQuery = lib.declare("SelectQuery", ctypes.default_abi, SelectQueryResult, GoString); | ||
|
||
module.exports = { | ||
Connect: function(connectionString) { | ||
return connect(makeGoString(connectionString)).p.readString(); | ||
}, | ||
Disconnect: function() { | ||
return disconnect().p.readString(); | ||
}, | ||
SelectQuery: function(qry) { | ||
var res = selectQuery(makeGoString(qry)); | ||
if(!res.r1.p.isNull()) { | ||
return res.r1.p.readString(); | ||
} | ||
return res.r0.p.readString(); | ||
} | ||
}; | ||
|
||
})(); |
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,24 @@ | ||
self.port.on("alert", function(msg) { | ||
window.alert(msg); | ||
}); | ||
|
||
self.port.on("select-query-results", function(results) { | ||
window.postMessage({action: "select-query-results", data: results}, "*"); | ||
}); | ||
|
||
window.addEventListener("message", function(evt) { | ||
var d = evt.data; | ||
switch(d.action) { | ||
case "connect": | ||
self.port.emit("connect", d.connectionString); | ||
break; | ||
case "disconnect": | ||
self.port.emit("disconnect", ""); | ||
break; | ||
case "select-query": | ||
self.port.emit("select-query", d.query); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); |
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,69 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>MySQL Admin for Firefox!</title> | ||
<style type="text/css"> | ||
#query-box { | ||
margin: 20px 0; | ||
background-color: whitesmoke; | ||
padding: 10px 0; | ||
} | ||
#query-box > * { | ||
display: block; | ||
} | ||
#select-query-box { | ||
float: left; | ||
} | ||
#select-query-results { | ||
float: left; | ||
font-family: courier; | ||
margin: 0 0 0 20px; | ||
max-width: 400px; | ||
white-space: pre-wrap; | ||
word-wrap: break-word; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>MySQL Admin for Firefox</h1> | ||
<div id="content"> | ||
<div id="connect-box"> | ||
<label for="connect-string-box">Connection String</label> | ||
<input type="text" id="connect-string-box"/> | ||
<button id="connect-button">Connect</button> | ||
<button id="disconnect-button">Disconnect</button> | ||
</div> | ||
<div id="query-box"> | ||
<button id="select-query-button">Run SELECT query</button> | ||
<textarea id="select-query-box" rows=20 cols=50></textarea> | ||
<pre id="select-query-results"></pre> | ||
<div style="clear: both;"></div> | ||
</div> | ||
</div> | ||
<script type="text/javascript" src="zepto/zepto.min.js"></script> | ||
<script type="text/javascript"> | ||
$(document).ready(function() { | ||
$("#connect-button").click(function() { | ||
window.postMessage({action: "connect", connectionString: $("#connect-string-box").val()}, "*"); | ||
}); | ||
$("#disconnect-button").click(function() { | ||
window.postMessage({action: "disconnect"}, "*"); | ||
}); | ||
$("#select-query-button").click(function() { | ||
window.postMessage({action: "select-query", query: $("#select-query-box").val()}, "*"); | ||
}); | ||
|
||
window.addEventListener("message", function(evt) { | ||
switch(evt.data.action) { | ||
case "select-query-results": | ||
$("#select-query-results").text(evt.data.data); | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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,4 @@ | ||
.PHONY: all | ||
|
||
all: | ||
go build -o firefox-mysql.so -buildmode=c-shared |
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,97 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"sync" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/jmoiron/sqlx" | ||
) | ||
|
||
import "C" | ||
|
||
var db *sqlx.DB | ||
|
||
//export Connect | ||
func Connect(uri string) string { | ||
if db != nil { | ||
return "Connection already open" | ||
} | ||
c, err := sqlx.Open("mysql", uri) | ||
if err != nil { | ||
return err.Error() | ||
} | ||
if err := c.Ping(); err != nil { | ||
return err.Error() | ||
} | ||
db = c | ||
return "OK" | ||
} | ||
|
||
//export Disconnect | ||
func Disconnect() string { | ||
defer func() { | ||
db = nil | ||
}() | ||
if db == nil { | ||
return "No connection to close" | ||
} | ||
if err := db.Close(); err != nil { | ||
return err.Error() | ||
} | ||
return "OK" | ||
} | ||
|
||
//export SelectQuery | ||
func SelectQuery(q string) (string, string) { | ||
if db == nil { | ||
return "", "No connection" | ||
} | ||
|
||
maps := make([]map[string]interface{}, 0) | ||
|
||
rows, err := db.Queryx(q) | ||
if err != nil { | ||
return "", err.Error() | ||
} | ||
for rows.Next() { | ||
out := map[string]interface{}{} | ||
err := rows.MapScan(out) | ||
if err != nil { | ||
return "", err.Error() | ||
} | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
// test that goroutines work | ||
go func() { | ||
defer wg.Done() | ||
for k, v := range out { | ||
if b, ok := v.([]byte); ok { | ||
out[k] = string(b) | ||
} | ||
} | ||
}() | ||
wg.Wait() | ||
maps = append(maps, out) | ||
} | ||
|
||
bytes, err := json.MarshalIndent(maps, "", " ") | ||
if err != nil { | ||
return "", err.Error() | ||
} | ||
return string(bytes), "" | ||
} | ||
|
||
//export Blah | ||
func Blah() (string, error) { | ||
return "", errors.New("test") | ||
} | ||
|
||
func main() { | ||
(Connect("root:root@/mysql")) | ||
fmt.Println(SelectQuery("SELECT * FROM user")) | ||
(Disconnect()) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,22 @@ | ||
{ | ||
"name": "zepto", | ||
"description": "Shim repository for the Zepto.js JavaScript library.", | ||
"version": "1.1.6", | ||
"main": "./zepto.js", | ||
"ignore": [ | ||
"*.md", | ||
".gitignore", | ||
"Makefile" | ||
], | ||
"homepage": "https://github.com/components/zepto", | ||
"_release": "1.1.6", | ||
"_resolution": { | ||
"type": "version", | ||
"tag": "1.1.6", | ||
"commit": "508d1a05bde2454251a86273ccef7a3368857719" | ||
}, | ||
"_source": "git://github.com/components/zepto.git", | ||
"_target": "~1.1.6", | ||
"_originalSource": "zepto", | ||
"_direct": true | ||
} |
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,11 @@ | ||
{ | ||
"name": "zepto", | ||
"description": "Shim repository for the Zepto.js JavaScript library.", | ||
"version": "1.1.6", | ||
"main": "./zepto.js", | ||
"ignore": [ | ||
"*.md", | ||
".gitignore", | ||
"Makefile" | ||
] | ||
} |
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,13 @@ | ||
{ | ||
"name": "zepto", | ||
"repo": "components/zepto", | ||
"description": "Shim repository for the Zepto.js JavaScript library.", | ||
"version": "1.1.6", | ||
"main": "zepto.js", | ||
"scripts": [ | ||
"zepto.js" | ||
], | ||
"files": [ | ||
"zepto.min.js" | ||
] | ||
} |
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,29 @@ | ||
{ | ||
"name": "components/zepto", | ||
"description": "Shim repository for the Zepto.js JavaScript library.", | ||
"type": "component", | ||
"keywords": [ | ||
"JavaScript" | ||
], | ||
"homepage": "http://zeptojs.com", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Thomas Fuchs", | ||
"homepage": "https://github.com/madrobby" | ||
} | ||
], | ||
"extra": { | ||
"component": { | ||
"scripts": [ | ||
"zepto.js" | ||
], | ||
"files": [ | ||
"zepto.min.js" | ||
], | ||
"shim": { | ||
"exports": "Zepto" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.