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
.
CRUD operations are same as MySql, just read Model -> Introduction.