Sutando

A modern Node.js ORM, like Laravel Eloquent.

README

Sutando logo

Sutando


Sutando is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. When using Sutando, each database table has a corresponding "Model" that is used to interact with that table. In addition to retrieving records from the database table, Sutando models allow you to insert, update, and delete records from the table as well.

Heavily inspired by Laravel's ORM Eloquent.


✨ Features


- Supports MySQL, PostgreSQL, SQLite and other databases
- Concise syntax and intuitive operations
- Model relationships for handling complex data queries and operations
- Powerful query builder
- Customized data type conversion for model attributes
- Easy-to-use transaction
- Support for hooks to execute custom logic at different stages of model operations
- Simple plugin mechanism for easy expansion

📖 Documentation


Check the full documentation on https://sutando.org | 中文文档

🚀 Quick Start


Let’s take mysql as an example.

Install Sutando and mysql database library

  1. ```sh
  2. $ npm install sutando mysql2 --save
  3. ```

The easiest way to make SQL queries is to use the Database query builder. It allows you to construct simple and complex SQL queries using JavaScript methods.

  1. ```js
  2. const { sutando, Model } = require('sutando');

  3. // Add SQL Connection Info
  4. sutando.addConnection({
  5.   client: 'mysql2',
  6.   connection: {
  7.     host : '127.0.0.1',
  8.     port : 3306,
  9.     user : 'root',
  10.     password : '',
  11.     database : 'test'
  12.   },
  13. });

  14. const db = sutando.connection();

  15. // Query Builder
  16. const users = await db.table('users').where('age', '>', 35).get();

  17. // ORM
  18. class User extends Model {}

  19. // Query Data
  20. const users = await User.query().where('age', '>', 35).get();

  21. // Insert
  22. const user = new User;
  23. user.name = 'David Bowie';
  24. await user.save();

  25. // Delete
  26. await user.delete();

  27. // Pagination
  28. const users = await User.query().paginate();

  29. // Eager Loading
  30. const users = await User.query().with('posts').get();

  31. // Constraining Eager Loads
  32. const users = await User.query().with({
  33.   posts: q => q.where('likes_count', '>', 100)
  34. }).get();

  35. // Lazy Eager Loading
  36. await user.load('posts');
  37. ```

💖 Show Your Support


Please ⭐️ this repository if this project helped you