PromiseDB is a Typescript ORM for automatic creation and management of models and entries from simple objects and arrays. It is designed to be used with any database, but currently only implements MariaDB/MySQL.
import { DatabaseManager, MariaDBConnection, BaseModel, EDatabaseTypes } from 'promisedb';
// const { DatabaseManager, MariaDBConnection, BaseModel, EDatabaseTypes } = require('promisedb');
// if you're only going to have a single connection you may pass it as parameter in DatabaseManager constructor and it will automatically register it under the name 'default'
const dbmgr = new DatabaseManager();
const mariadb = new MariaDBConnection('localhost', 3306, 'username', 'password', 'database');
await dbmgr.registerConnection('prodmaria', mariadb);
// You can also extends BaseModel in a class and pass the params to super() if you wish to instantiate your models all a once somewhere else.
const iceCreamModel = new BaseModel({
flavor: {
type: EDatabaseTypes.STRING,
maxSize: 50, // 50 characters string
nullable: false,
unique: true,
primaryKey: true,
},
price: {
type: EDatabaseTypes.DECIMAL,
maxSize: 999.99, // $999.99
minSize: 0, // $0.00
nullable: false,
},
});
// Optionally, you can use the MariaDBConnection instance object instead of calling get connection.
const iceModel = await dbmgr.getConnection('prodmaria').registerModel('icecream', iceCreamModel);
iceModel.create({
flavor: 'chocolate',
price: 9.99,
}).then(async () => {
console.log('Successfully created item on database!');
console.log(await iceModel.findOne({ flavor: 'chocolate' }));
});
/* Output:
> Successfully created item on database!
{ flavor: 'chocolate', price: '9.99' }
*/
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
You can find the full changelog under the markdown CHANGELOG.md file.
Contributions is what makes the open source community an amazing place and its a wonderful place to learn, inspire and create. Any contribution you make will be very much appreciated.
- Make a Fork of the Project
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
LoboMetalurgico |
SpaceFox |
Made with 💜 By PromisePending™'s team.