English
Getting started
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.
Sutando is highly inspired by Eloquent as the behaviour is pretty much the same.
Quick Started
Install Sutando and mysql database library
sh
npm install sutando mysql2 --save
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.
In the following example, we select all the posts from the users table.
js
const { sutando, Model } = require('sutando');
// Add SQL Connection Info
sutando.addConnection({
client: 'mysql2',
connection: {
host : '127.0.0.1',
port : 3306,
user : 'root',
password : '',
database : 'test'
},
});
const db = sutando.connection();
// Using The Query Builder
const users = await db.table('users').where('votes', '>', 100).get();
// Using The Schema Builder
await sutando.schema().createTable('users', table => {
table.increments('id').primary();
table.integer('votes');
table.timestamps();
});
// Using The ORM
class User extends Model {}
const users = await User.query().where('votes', '>', 100).get();