0.3.17 • Published 7 years ago

smart-mysql-cache v0.3.17

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

Smart MySQL Cache

smart-mysql-cache Storing Content The Database In Disk.

So let's build it with JavaScript.

How to Install :

$ npm install smart-mysql-cache

How to connect :

To use this library should we calling cache class.

host , user , password , charset , database , collection is required .

var {cache} = require('smart-mysql-cache');

var collection = {
tbl_user : {
attributes : [
{ name : 'id' , empty : false },
{ name : 'fullname' , empty : '' },
{ name : 'username' , empty : '' },
{ name : 'password' , empty : '' }
]
},
tbl_post : {
attributes : [
{ name : 'id' , empty : false },
{ name : 'title' , empty : '' },
{ name : 'description' , empty : '' },
{ name : 'user' , empty : false , collection : 'tbl_user' }
]
}
};

var db = new cache({ mysql : {
    host : 'localhost',
    user : 'root',
    password : '',
    charset : 'utf8_unicode_ci',
    database : 'avl'
} , collection });

Specify your table :

It’s easy to define which table you wants to work with. You can specify your table name as we have done below.

db.collection('table_name');

Inserting Rows :

We'll show you, That's simple to insert the records.

db.collection('tbl_user').add({ fullname : 'hamid afsordeh' , username : 'hamid' , password : '******' });
db.collection('tbl_post').add({ title : 'The First Post' , description : 'This Is First Post' , user : 1 });

Updating Rows :

Update your table simply. This line update all of your rows with condition. Use put new data in first parameter. Next line will update all of your columns named username.

db.collection('tbl_user').get(5).data = { username : 'hamid_afsordeh' };

This sql query happen for last command:

Update tbl_user set username = 'hamid_afsordeh'

Delete a Row :

It’s simple to delete a row from table with that condition you want or Without any condition as we have done below.

db.collection('tbl_post').get(5).delete;

Last command return this query string:

Delete from tbl_user where id = 5

Selecting Rows :

There is three way to use select function

  1. find
  2. first
  3. get
  4. all
  1. In all function you will take all of rows that you want to be. You can use this parameters for table function.

db.collection('tbl_post').all

You can set condition in second parameter for select

db.collection('tbl_post').filter((post) => { return post.id == 5 });

OR use many condition

db.collection('tbl_post').filter((post) => { return post.id == 5 && post.user == 1 });

find , first and get:

  1. In find , fist and get function you take only one row of table as we have done below. You can use this function like table function. But different is this function fetch first row.

find(filter);

first();

get(id);

db.collection('tbl_user').find({ id: 5 });

db.collection('tbl_user').first();

db.collection('tbl_user').get(5);

Last commands return this query, string.

Select * from tbl_user where id = 5

Select * from tbl_user Limit 1

Select * from tbl_user where id = 5

0.3.17

7 years ago

0.3.16

7 years ago

0.3.15

7 years ago

0.3.14

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago