LocalJsonPersist constructor
Saves to appDocsDir/db/${dbName}.json
If dbName
is a String, it will be used as such.
If dbName
is an enum, it will use only the enum value itself.
For example if files
is an enum, then LocalJsonPersist(files.abc)
is the same as LocalJsonPersist("abc")
If dbName
is another object type, its toString will be called,
and then the text after the last dot will be used.
The default database directory defaultDbSubDir is db
.
You can change this variable to globally change the directory,
or provide dbSubDir
in the constructor.
You can also provide other subDirs
as Strings or enums.
Example: LocalJsonPersist("photos", subDirs: ["article", "images"])
saves to appDocsDir/db/article/images/photos.db
Important:
— In tests, instead of using appDocsDir
it will save to
the system temp dir.
— If you mock the file-system (see method setFileSystem()
)
it will save to fileSystem.systemTempDirectory
.
Implementation
LocalJsonPersist(Object dbName, {this.dbSubDir, List<Object>? subDirs})
: dbName = _getStringFromEnum(dbName),
subDirs = subDirs?.map((s) => _getStringFromEnum(s)).toList(),
_file = null,
_fileSystemRef = _fileSystem;