sequelize-db-storage-files

1.2.0 • Public • Published

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

Dependents (0)

Package Sidebar

Install

npm i sequelize-db-storage-files

Weekly Downloads

19

Version

1.2.0

License

ISC

Unpacked Size

43.5 kB

Total Files

38

Last publish

Collaborators

  • maut_dev