Giter Club home page Giter Club logo

json-database's Introduction

Json-db by Lepola

Simple json db javascript library, create json 'tables' and save data to it.

Requires JQuery, PHP.

Getting start

PHP for login and logout, Javascript for edit, delete and get table / item.

  1. Copy json-db folder to your website.

  2. Open json-db/config.php and set your database username and password.

  3. For editing, creating or deleting tables / items and selecting protected table data, you need login with php:

     - include 'json-db/config.php';
     - json_db_login($yourusername, $yourpassword);
    
  4. After this you can edit tables with Javascript using json-db/json-db.js.

  5. json-db/index.php is simple adminpanel for db.

PHP functions

  1. include 'config.php';

Log in with config.php username and password.

json_db_login($USERNAME, $PASSWORD);



Logout

json_db_logout();



If you are logged in -> return true, else return false.

json_db_logged_in();

Javascript (json-db.js) functions

Response message format:

{

	response: (object), // if error is 1, this won't exist.

	message: (string),

	error: (0 = No error, 1 = error)

}

Json db library path

json_db.folder.path = "json_db/"; // This is default path. This needs to be valid and <b>use slash at end of path!</b>

Create table, eg:

json_db.createTable("tableName", function(response){

	console.log(response);

});

Create Protected table, you can read only if you are logged in. eg:

json_db.createProtectedTable("tableName", function(response){

	console.log(response);

});

Update table protected status. eg:

json_db.updateTableContent(TABLE_NAME, PROTECTED_STATUS, SUCCESS_FUNCTION);

json_db.updateTable("tableName", 1 /*1 = protected, 0 = non-protected*/, function(response){

	console.log(response);

});

Update table content. This replace old table to JSON_VARIABLE parameter. eg:

json_db.updateTableContent(TABLE_NAME, JSON_VARIABLE, SUCCESS_FUNCTION);

json_db.updateTableContent("tableName", {"name": "test"}, function(response){

	console.log(response);

});

Remove table eg:

json_db.removeTable("tableName", function(response){

	console.log(response);

});

Get table eg:

json_db.getTable("tableName", function(response){

	console.log(response);

});

Get all tables eg:

json_db.getTables(function(response){

	console.log(response);

});

Get item eg:

json_db.getItem(TABLE_NAME, ITEM_INDEX, SUCCESS_FUNCTION);

json_db.getItem("tableName", 0, function(response){

	console.log(response);

});

Edit item eg:

json_db.editItem(TABLE_NAME, ITEM_INDEX, NEW_ITEM, SUCCESS_FUNCTION);

json_db.editItem("tableName", 0, {"item":"newItem"}, function(response){

	console.log(response);

});

Add item eg:

json_db.addItem(TABLE_NAME, ITEM, SUCCESS_FUNCTION);

json_db.addItem("tableName", {"title":"this item will be added."}, function(response){

	console.log(response);

});

License

GNU General Public License v3.0

json-database's People

Contributors

lepola avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.