我想直接从javascript脚本将数据存储在SQLite数据库中.我发现这个SQL.js库是javascript的一个端口.但是,显然它只适用于coffeescript.有谁知道如何在JavaScript中使用它?关于如何在SQLite DB中存储数据的其他想法也受到欢迎.
lov*_*soa 10
我是最新版本的sqlite到javascript的这个端口的作者:https://github.com/lovasoa/sql.js
它基于您提到的(https://github.com/kripken/sql.js),但包含许多改进,包括完整的文档:http://lovasoa.github.io/sql.js/documentation/
以下是如何使用此版本的示例 sql.js
<script src='js/sql.js'></script>
<script>
//Create the database
var db = new SQL.Database();
// Run a query without reading the results
db.run("CREATE TABLE test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);
// Prepare a statement
var stmt = db.prepare("SELECT * FROM test WHERE col1 BETWEEN $start AND $end");
stmt.getAsObject({$start:1, $end:1}); // {col1:1, col2:111}
// Bind new values
stmt.bind({$start:1, $end:2});
while(stmt.step()) { //
var row = stmt.getAsObject();
// [...] do something with the row of result
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16032 次 |
| 最近记录: |