npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

autojs-sqlite

v1.1.7

Published

autojs中二代api里esm环境下使用sqlite数据库的orm框架,风格参考sequelize

Readme

autojs-sqlite 使用示例

作者:抠脚本人

仿照 sequelize 风格封装的 autojs 中用的 orm 数据库框架,通过调用安卓的 SQLiteDatabase 封装,以下是使用的例子

导入资源

import { DataTypes, SQLite } from "autojs-sqlite";

新建名为 test 的 SQLite 数据库对象,并强制同步数据库文件

const mSqlite = new SQLite("test", { force: true });

通过原生的 SQL 语句创建学生表

const Student = mSqlite.rawCreateTable(
	"STUDENT",
	`CREATE TABLE IF NOT EXISTS STUDENT(
		'id' INTEGER PRIMARY KEY AUTOINCREMENT,
		'name' TEXT NOT NULL,
		'age' INTEGER,
		'score' INTEGER
	) `
);

使用内置的封装创建教师表

const Teacher = mSqlite.createTable("TEACHER", {
	id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, //以id为主键,数字类型自动递增
	name: { type: DataTypes.TEXT, notNull: true }, //姓名不能为空
	man: { type: DataTypes.BOOLEAN, defaultValue: 1 }, //布尔值,0为女教师,1为男教师,默认为男教师
	project: { type: DataTypes.TEXT, unique: true }, //将学科作为唯一键,避免重复添加
	age: DataTypes.INTEGER, //年龄为数字类型,可为空
});

增加 4 行学生信息

Student.insert([
	{ name: "测试1", age: 15, score: 55 },
	{ name: "测试2", age: 16, score: 66 },
	{ name: "测试3", age: 17, score: 77 },
	{ name: "测试4", age: 18, score: 95 },
]);

开启事务

mSqlite.begin(function (sqlite) {
	console.log(sqlite.inTransaction);
});

在事务中删除

Student.delete({
	score: { "<": 60 },
});

查询所有学生,可以看到 score 小于 60 的学生被删除

console.log(Student.query());

放弃事务,修改回滚

mSqlite.end();

回滚后,数据已恢复,还是 4 条学生信息

console.log(Student.count());

事务提交并修改生效

mSqlite.begin(function (sqlite) {
	//getTable("STUDENT") 同样拿到 Student 学生表,方便不需要新建表的场景使用
	sqlite.getTable("STUDENT").delete({
		score: { "<": 60 },
	});
	//通过merge标记事务成功并结束事务
	mSqlite.merge();
});

通过查询可以看出修改已生效

console.log(Student.query());

增加两行教师信息,返回增加的主键 id 数组

Teacher.insert([
	{ name: "王老师", age: 45, project: "语文" },
	{ name: "李老师", age: 36, project: "英语" },
]);

增加一行教师信息,可以用 insertItem,返回增加的主键 id

console.log(Teacher.insertItem({ name: "张老师", age: 45, project: "数学" }));

新增一行,由于 project 为唯一键,"数学"重复,返回-1,代表新增数据失败。且控制台会有日志提示

console.log(Teacher.insertItem({ name: "赵老师", age: 49, project: "数学" }));

第二个参数为 true,代表遇到唯一键时,更新信息,返回更新的主键值

console.log(Teacher.insertItem({ name: "赵老师", age: 49, project: "数学" }, true));

更新 project 为"数学"教师的 age 为 42

console.log("更新行数:", Teacher.update({ age: 42 }, { project: "数学" }));

查询 name 不等于"测试 4",age 大于 15,小于 19 的学生

console.log(
	Student.query({
		name: { "!=": "测试4" },
		age: {
			">": 15,
			"<": 19,
		},
	})
);

查找 project 为语文的教师

console.log(
	Teacher.findOne({
		project: "语文",
	})
);

查找主键值为 2 的教师

console.log(Teacher.findByPk(2));

查找 name 为 "张老师" 的教师

console.log(Teacher.query({ name: "张老师" }));

使用原始 query 语句查询 name 是"测试 1"的学生

let result = mSqlite.rawQuery("SELECT * FROM STUDENT WHERE name = ?", ["测试1"]);
console.log("result:", result);

使用原始 sql 语句,执行删除 name 是"测试 1"的学生。注意看安卓文档,原始 sql 命令的适用场景

mSqlite.rawSql("DELETE FROM STUDENT WHERE name = ?", ["测试1"]);

关闭数据库引用

mSqlite.close();