vpan.cn API 文档

SqlCE操作 | 返回上页
dbx(4)
* 参数写在 select 里面,需要先 cast 转换类型,例如 db().scalar("select cast(@title as ntext)", { title: "欢迎" });
ErrPage: 建表
@form { }
[检视源码]
function(err) {
	if(err.number != -2147467259) return err.message;
	dbx(4).create("users", [
		["id int", null, true], "nick nvarchar(16)", "icon nvarchar(254)",
		"phone nvarchar(16)", "pass nvarchar(32)", "openid nvarchar(32)", "memo ntext",
		[ "regtime datetime", "getdate()" ]
	]);
	dbx(4).none("create index phone on users(phone)");
	dbx(4).none("create index openid on users(openid)");
	dbx(4).create("wxpaylog", [
		[ "id int", null, true ], "userid int", "openid nvarchar(32)",
		"tradewx nvarchar(32)", "tradeno nvarchar(32)", "fee int",
		"apiname nvarchar(32)", "apivalue nvarchar(32)", "memo ntext",
		[ "paytime datetime", "getdate()" ]
	]);
	dbx(4).none("create unique index tradewx on wxpaylog(tradewx)");
	dbx(4).none("create index tradeno on wxpaylog(tradeno)");
	dbx(4).none("create index userid on wxpaylog(userid)");
	return "table users inited.";
}
Home: 首页调用
@form { }
[检视源码]
function() {
	sys.title = dbx(4).scalar("select cast(@title as ntext)", { title: "首页 | Pojin 博客" });		// scalar  // 参数写在 select 里面,需要先 cast 转换类型是取数据库第1行第1列,为了测试数据库中文支持是否正常
	// try { var rows = dbx(4).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 echo("error"); }
	//var par = {};
	var list = dbx(4).table("info a").join("catalog b on b.id=a.cataid").
		where("a.state=1 and b.kind=0 and b.state=1").
		select("top 10 b.name, a.id, a.title, a.pubtime, a.ext, a.intro, datediff(d, a.pubtime, getdate()) as isnew").orderby("a.id desc").query();
		//调取10个id 可以这样写 .orderby("a.id desc").limit(0, 10).query(par); 也可以这样写 .orderby("a.id desc limit 0, 10").query();
	return { title: sys.title, list: list };
}
参数录入
执行
取消