This JavaScript project provides a convenient and simple way to handle SQL queries in your applications. It consists of a concrete class that can be easily extended for each table in your database.
To integrate this project into your repository, follow these steps:
-
Add this project as a git template:
git remote add template https://github.com/your-template-repo.git git fetch template git merge --allow-unrelated-histories template/main
To use this SQL query handler, follow these steps:
-
Create a class for each table you need to interact with.
-
Make these classes inherit from the provided
modelclass. -
Utilize the following methods on instances of your new inherited class objects:
update: Update a record in the database.load: Load a single record from the database.loadmany: Load multiple records from the database.save: Save a new record to the database.delete: Delete a record from the database.
-
When calling these methods use await
import Model from './Model.js';
export default class Task extends Model {
static table = "schema.tasks";
static primary = ["id"];
// Additional methods or properties specific to the 'schema.tasks' table can be added here.
}Feel free to contribute by submitting issues or pull requests. Any feedback or improvements are highly appreciated!
This project is licensed under the MIT License - see the LICENSE.md file for details.
Note: This code is almost entirely copied from Khoi Nguyen, and I'm giving him all the credits for the original implementation.