sqlite是一个非常小的数据库,适合小的应用,或者是app之类的.
install
下载SQLite , 下载的文件是sqlite-shell-win32-x86-3081001.zip
下载后将sqlite3.exe放入到windows系统的path路径中,或者在pathe路径中加入sqlite3.exe所在的目录。
可以使用GUI工具 , 这个应该更方便
using command, such as:
1
sudo yum install sqlite-devel
commands
打开或者创建一个数据库.
1
2
3
4
5
6
7
8
9
$ sqlite3 ex1
SQLite version 3.8.5 2014-05-29 12:36:14
Enter ".help" for usage hints.
sqlite> create table tbl1( one varchar( 10) , two smallint) ;
sqlite> insert into tbl1 values( 'hello!' ,10) ;
sqlite> insert into tbl1 values( 'goodbye' , 20) ;
sqlite> select * from tbl1;
hello!|10
goodbye|20sqlite>
Other command:
1
2
3
4
5
6
sqlite> .tables # 查看table list
sqlite> .schema ?TABLE? # 查看table的create语句
sqlite> .help # 查看help信息
sqlite> .exit # 退出
sqlite> select * from tbl1; # 执行sql语句
sqlite> .indexes ?TABLE? # 查看table的index
using sqlite3 in a shell script:
1
2
3
4
5
$ sqlite3 ex1 'select * from tbl1' |
> awk '{printf "<tr><td>%s<td>%s\n",$1,$2 }'
<tr><td>hello<td>10
<tr><td>goodbye<td>20
$
文档 https://www.sqlite.org/cli.htmlmore documents:
SQLite documents
SQLite Syntax or SQLite Syntax
node.js for SQLite
SQLite有不同的client,这里一个node为例: node-sqlite3
这里一个代码的例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var sqlite3 = require ( 'sqlite3' ). verbose ();
var db = new sqlite3 . Database ( ':memory:' );
db . serialize ( function () {
db . run ( "CREATE TABLE lorem (info TEXT)" );
var stmt = db . prepare ( "INSERT INTO lorem VALUES (?)" );
for ( var i = 0 ; i < 10 ; i ++ ) {
stmt . run ( "Ipsum " + i );
}
stmt . finalize ();
db . each ( "SELECT rowid AS id, info FROM lorem" , function ( err , row ) {
console . log ( row . id + ": " + row . info );
});
});
db . close ();
API document
安装的最简单方法是使用npm: