DB-Connector : Simple way of dealing with databases
Contents
Key Features
- Reads data from databases (Currently supports Cassandra and Neo4J)
- Executes queries and converts result set to List<> of Map<String, Object>
- Read data as List when only one column is being read
Usages
- Integrate into automation frameworks for data validation
- Connect with database and run
SELECT
queries - Easy to use data in validations while dealing just with
List
andMap
objects
Limitations
- Currently supports CASSANDRA AND GRAPH DATABASES ONLY
- Currently supports to execute retrieve queries only. Add/Update/Delete support to follow.
Examples
CASSANDRA
Create connection and session
Connector dbConnector = new Cassandra(contactPoints,keyspace, username, password);
- Creates a connection to specified keyspace
- Session is available on dbConnector object to execute queries
Read from CASSANDRA
For a query like SELECT * FROM <TableName>
List<String> args = new ArrayList<>();
List<Map<String, Object>> data = dbConnector.getData(statement, args);
- Passes an empty args list to library and returns each row as a map
- For queries that has filtering conditions, add variables in same sequence as query to the args list
For a query like SELECT <ColumnName> from <TableName>
List<Map<String, Object>> data = dbConnector.getKey(statement, args);
- Returns the values from the queried column in a list, each value is read as a String
GRAPH
Create connection and session
Connector dbConnector = new Graph(url,username,password);
- Creates a connection to specified database box in the url. Incase of proxy, connection is made to master
- Session is available on dbConnector object to execute queries