Giter Club home page Giter Club logo

ethereum-user-db-service's Introduction

MariaDB database access module

Installation

npm install eth-db-service  -g

Usage

The module assumes that mariaDB is running on the host under alias: user-db. Make sure you name the MariaDB image with this alias in your docker-compose deployment!

const DbService = require('eth-db-service');
var dbService = new DbService();

Every method returns a promise with the result.

Check if mobileMapping table exists

dbService.checkIfMobileMappingTableExists()
.then(function(result) {
    if(result.lenght == 0) {
      console.log("Tabled does not exist!";)
    }
    //users is an array of user objects
}).catch(function handleError(error) {
    //your error handling goes here
});

Check if userCredentials table exists

dbService.checkIfUserCredentialsTableExists()
.then(function(result) {
    if(result.lenght == 0) {
      console.log("Tabled does not exist!";)
    }
    //users is an array of mapping objects 
}).catch(function handleError(error) {
    //your error handling goes here
});

Create mobile mappings table

The table will have two rows:

  • address (primary key): the secondary Ethereum address
  • value : information used to send the push notification to the mobile App that registered the address
dbService.createMobileMappingTable(message,address,password)
.then(function() {
    //do something aftewards
}).catch(function handleError(error) {
    //your error handling goes here
});

Create mobile usersCredentials table

The table will have two rows:

  • email (primary key)
  • authenticationKey : the primary Ethereum address
dbService.createUserCredentialsTable(message,address,password)
.then(function() {
    //do something aftewards
}).catch(function handleError(error) {
    //your error handling goes here
});

Insert new user

dbService.insertUserCredentials(email, authenticationKey)
.then(function() {
    //do something aftewards
}).catch(function handleError(error) {
    //your error handling goes here
});

Insert new mapping

dbService.insertMapping(address, value)
.then(function() {
    //do something aftewards
}).catch(function handleError(error) {
    //your error handling goes here
});

Get user by email

dbService.getUserCredentialsByEmail(email)
.then(function(user) {
    var email = user.emai;
    var authenticationKey = user.authenticationKey;
}).catch(function handleError(error) {
    //your error handling goes here
});

Get mapping by secondary address

dbService.getMappingByAddress(address)
.then(function(mapping) {
    var address = mapping.address;
    var secondaryKey = mapping.value;
}).catch(function handleError(error) {
    //your error handling goes here
});

Get all users

dbService.getUserCredentials()
.then(function(users) {
    //users is an array of user objects
}).catch(function handleError(error) {
    //your error handling goes here
});

Get all mappings

dbService.getMappings()
.then(function(mapping) {
    //users is an array of mapping objects
}).catch(function handleError(error) {
    //your error handling goes here
});

Dependencies

  • mysql npm install mysql --save
  • Q npm install q --save

ethereum-user-db-service's People

Contributors

ivozielinski avatar

Watchers

James Cloos 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.