Skip to content

A Typescript ORM for automatic creation and management of models and entries from simple objects

License

Notifications You must be signed in to change notification settings

PromisePending/PromiseDB

Repository files navigation

PromiseDB

License

📖 About

    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.

Usage

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' }

*/

📝 License

    This project is licensed under the GPL-3.0 License - see the LICENSE file for details.


📜 Changelog

    You can find the full changelog under the markdown CHANGELOG.md file.


🤝 Contributing

    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.

  1. Make a Fork of the Project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

😉 Authors


LoboMetalurgico's GitHub profile logo
LoboMetalurgico
SpaceFox's GitHub profile logo
SpaceFox

Made with 💜 By PromisePending™'s team.

About

A Typescript ORM for automatic creation and management of models and entries from simple objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published