sequelize-db-storage-files
v1.2.0
Published
## Install ```bash npm i sequelize-db-storage-files ```
Downloads
25
Maintainers
Readme
Database file storage
Install
npm i sequelize-db-storage-files
Initialization
import { DbStorageFiles } from "sequelize-db-storage-files";
import { Sequelize } from "sequelize-typescript";
const sequelize = new Sequelize({
// ... options
});
const dbStorageFiles = new DbStorageFiles(sequelize);
await sequelize.sync();
Create File
const file = await dbStorageFiles.write('/text.txt', Buffer.from('Hello, World!'));
Get File
const file = await dbStorageFiles.getFromPath('/text.txt');
if(!file) throw new Error("Not found File");
const text = (await file.getFileData()).data.toString('utf-8');
console.log(text); // Hello, World!
File Info
file.id // string(uuidv4)
file.z // string
file.hash // string (sha256)
file.info // string (json)
file.size // number (bytes)
file.deletionDate // Date | null
file.createdAt // Date
file.updatedAt // Date
DbStorageFile
and DbStorageFileData
are sequelize models, so all the methods in the sequelize documentation apply to them