npm install eth-db-service -g
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.
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
});
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
});
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
});
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
});
dbService.insertUserCredentials(email, authenticationKey)
.then(function() {
//do something aftewards
}).catch(function handleError(error) {
//your error handling goes here
});
dbService.insertMapping(address, value)
.then(function() {
//do something aftewards
}).catch(function handleError(error) {
//your error handling goes here
});
dbService.getUserCredentialsByEmail(email)
.then(function(user) {
var email = user.emai;
var authenticationKey = user.authenticationKey;
}).catch(function handleError(error) {
//your error handling goes here
});
dbService.getMappingByAddress(address)
.then(function(mapping) {
var address = mapping.address;
var secondaryKey = mapping.value;
}).catch(function handleError(error) {
//your error handling goes here
});
dbService.getUserCredentials()
.then(function(users) {
//users is an array of user objects
}).catch(function handleError(error) {
//your error handling goes here
});
dbService.getMappings()
.then(function(mapping) {
//users is an array of mapping objects
}).catch(function handleError(error) {
//your error handling goes here
});