ThinkJS supports SQLite database, underlying uses sqlite3 module.
Change type
property to sqlite
to use SQLite. Modify src/common/config/db.js
:
export default {
type: "sqlite"
}
SQLite supports two ways to store data: memory and file, config path
to true
to use memory store:
export default {
type: "sqlite",
adapter: {
sqlite: {
path: true, // use memory to store data
}
}
}
Use file need to set the path of SQLite data, default is src/common/runtime/sqlite
.
export default {
type: "sqlite",
adapter: {
sqlite: {
path: "/path/to/store/sqlite" //use file to store data
}
}
}
The path of data file is path
+ /[name].sqlite
, default database demo
's file path is src/common/runtime/sqlite/demo.sqlite
.
CURD operations are same as MySql, just read Model -> Introduction.
This doc stays at https://github.com/75team/www.thinkjs.org/tree/master/view/zh-cn/doc/2.0/model_sqlite.md.