Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 

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

About

npm module used to perform database operations in mariadb

Resources

License

Releases

No releases published

Packages

No packages published