vpan.cn API 文档

SQLite操作 | 返回上页
dbx(1)
*
ErrPage: 建表
@form { }
[检视源码]
function(err) {
	if(err.number != -2147467259) return err.message;
	dbx(1).create("users", [
		["id integer", null, true], "nick varchar(16)", "icon varchar(254)",
		"phone varchar(16)", "pass varchar(32)", "openid varchar(32)", "memo text",
		[ "regtime timestamp", "datetime('now','localtime')" ]
	]);
	dbx(1).none("create index phone on users(phone)");
	dbx(1).none("create index openid on users(openid)");
	dbx(1).create("wxpaylog", [
		[ "id integer", null, true ], "userid integer", "openid varchar(32)",
		"tradewx varchar(32)", "tradeno varchar(32)", "fee integer",
		"apiname varchar(32)", "apivalue varchar(32)", "memo text",
		[ "paytime timestamp", "datetime('now', 'localtime')" ]
	]);
	dbx(1).none("create unique index tradewx on wxpaylog(tradewx)");
	dbx(1).none("create index tradeno on wxpaylog(tradeno)");
	dbx(1).none("create index userid on wxpaylog(userid)");
	return "table users inited.";
}
Home: 首页调用
@form { }
[检视源码]
function() {
	sys.title = dbx(1).scalar("select @title", { title: "首页 | Pojin 博客" });		//scalar 是取数据库第1行第1列,为了测试数据库中文支持是否正常
	try { var rows = dbx(1).table("users").where("id % @mod = 1").
		page("id", sys.pagenum, 2, { mod: 2 }).astable("a").join("users b on b.id=a.id+1").
		select("a.id, a.nick, b.id as fid, b.nick as friend, a.regtime").
		query(); }
	catch(err) { return root.sql.sqlite.errPage(err); }
	//var par = {};
	var list = dbx(1).table("info a").join("catalog b on b.id=a.cataid").
		where("a.state=1 and b.kind=0 and b.state=1").
		select("b.name, a.id, a.title, a.pubtime, a.ext, a.intro, julianday('now') - julianday(a.pubtime) <=1 as isnew").orderby("a.id desc limit 0, 10").query();
		//调取10个id 可以这样写 .orderby("a.id desc").limit(0, 10).query(par); 也可以这样写 .orderby("a.id desc limit 0, 10").query();
	return { list: list, rows: rows, pager: dbx(1).pageArg };
}
参数录入
执行
取消