mysqloose
This is similar to mongoose but for mysql
warning: Don not use this in real project, it is unstable
Installation
You need: Node.js installed on your machine.
To install
$ npm i mysqloose
Importing
const mysqloose = ;
Important: Turn on mysql server before using
Overview
Connecting to MySQL
First, we need to define a connection.
mysqloose;
Defining a Model
Models are defined through the Schema interface. Unlike mongoose, you can not define a model without mysqloose.connect
mysqloose; const Schema = mysqlooseSchema; const UserSchema = id: 'INT NOT NULL AUTO_INCREMENT PRIMARY KEY' // mysqloose do not have ObjectId yet user_name: 'VARCHAR(40) NOT NULL' email: 'VARCHAR(255) NOT NULL' password: 'varchar(60) not null' // Case-insensitive user_type: 'varchar(5) default "user"';
Accessing a Model
const User = mongoose; const newUser = user_name: "user name" email: "email" password: "password";
Insert
newUser;
Select
Synchronous
User; // Must use {<somethingId>: <number>}User; User;
Asynchronous
User ; User ; User ;
Update
User;
Delete
User;
Model API
create( object, callback)
find( object, string, callback )
findOne( object, string, callback )
findOneAndUpdate( object, object, callback )
findOneAndDelete(object, callback )
findById( object, string, callback )
findByIdAndUpdate( object, object, callback )
findByIdAndDelete( object, callback )
updateOne( object, object, callback )
updateMany( object, object, callback )
deleteOne( object, callback)
deleteMany( object, callback)