-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mapepire: A new IBM i database client #68
Comments
Nice one ! Cant wait to play around with it when I get a chance. |
Will this be the ultimate and only ODBC driver from IBM and get regular updates? |
Getting an unknown host acceprtion, how to resolve this?
|
@GajenderI please raise your issue in the Mapepire-server repo. Thanks! |
@worksofliam would you please confirm this. |
@GajenderI ODBC and Mapepire will both exist. ODBC is not going away. |
it would be great if a JDBC driver is built to leverage Mapepire java client. |
@chiragsanghavi Implementing a driver will be looked at soon. The status of this can be tracked here |
Hi @worksofliam, |
IBM have been quietly working on brand new database clients for Db2 for IBM i, with the requirement that no native binaries will be required in the clients to connect to the database.
That is how ODBC currently works; you install the IBM i Db2 ODBC database driver, then install (and sometimes build) the ODBC client into the runtime you're using (for example, node-odbc or pyodbc). There were problems with this: there are some platforms that ODBC cannot run on and also in some instances is not able to run in a container, though it is possible.
Today, August 30th, is the first day that Mapepire (pronounced ‘mapəpɪə’ or ‘MAH-pup-ee’) is really usable. We've got all the documentation ready to go, multiple clients ready, and sample applications ready to go.
This post is co-written by Adam Shedivy, Sanjula Ganepola, and myself. Each of us worked on multiple components of Mapepire and we're coming together to write about Python, Java and Node.js respectively.
Why a new server/client?
Typically with IBM i, the database/server clients take on very heavy loads. For example, jtopen and ODBC clients have code inside of them to deal with CCSIDs - converting string columns to and from certain encodings. This makes client very large in code but also in complexity. Another ick that I've always had with ODBC and jtopen is that the protocol used to communicate between the server and clients is not publically documented (or at least, very well). So, if you want to create a new client in a new language you have to reverse engineer what is available - I tried it, it sucked.
Mapepire takes a brand new approach. Almost every part of Mapepire is open-source. This includes the server, the protocol and the clients. As well as that, we're letting the server piece take care of things like encodings, password levels, and much more, which makes the clients lighter. We're going to make it easier for people to write new applications in more languages that can run on more platforms.
Another benefit is that we're going to use yum and typical registires for different languages (npm for our Node.js client, pypi for Python, Maven for Java, etc). This means we can ship updates and fixes to you faster than before.
Getting the server ready
For your clients to use Mapepire, a new server component will need to be installed and started onto the server. This is a server just like many of the other system services - it's just managed differently because we are shipping through yum instead of PTF.
You can check if Mapepire is available and install it with yum:
Following the installation, you can use Service Commander to start the Mapepire server:
Never heard of Service Commander? Install it with
yum install service-commander
and also checkout this blog entry by Jesse Gorzinski.Building apps
The best way to show you working apps is to show off our app samples. As of this post being written, we only have Java, Python and Node.js samples. As more client libraries are built, more samples will be shown off.
The sample applications can be found on GitHub.
Python
To use the Python Client, first install the
mapepire-python
package:Python 3.9 or later required
Setup the server credentials used to connect to the server. One way to do this is to create a
mapepire.ini
file in the root of your project with the following content:The following script sets up a
DaemonServer
object that will be used to connect with the Server Component. Then a singleSQLJob
is created to facilitate the connection from the client side.Here is the output from the script above:
For more in depth usage, refer to the Python Client docs:
Java
Getting started with the Java client (
mapepire-sdk
) is as easy adding amaven
dependency in your project:Note: Make sure to check out the latest version on the Maven Central Repository.
From there, you can establish a connection, execute queries, and parse queries using the very intuitive APIs provided by the package:
We also put together several sample project's that can also be used as a starting point.
1. simple-app
For those looking to play around with the different APIs, the
simple-app
project is the best place to have a try with using the various APIs and observing what the output is through the command line.Ensure the Mapepire Server is installed and running on the IBM i.
Clone the repository:
git clone https://github.com/Mapepire-IBMi/samples.git cd java/simple-app
Copy and fill out the configuration properties:
Build the application:
Run the application:
Replace
<demo-type>
in the above command with one of the demo types below:--sql
--prepareStatement
--clCommand
--paginatingResults
--pooling
--jdbcOptions
2. company-web-server
For those looking for a more advanced project, definitly check out the
company-web-server
which is a simply a Jetty webserver that can be used to manage departments, employees, and sales.Ensure the Mapepire Server is installed and running on the IBM i.
Create the
SAMPLE
schema on the IBM i:Clone the repository and build the application:
git clone https://github.com/Mapepire-IBMi/samples.git cd java/company-web-server mvn clean package
Start the company web server:
cd target java -jar company-web-server-1.0-SNAPSHOT-jar-with-dependencies.jar
Start a web server to launch the Swagger UI:
npm install -g http-server cd swagger http-server --cors
Access the Swagger UI at http://localhost:8080 in the browser.
Connect to a database using the
/connect
endpoint.Set the server trace level using the
/tracing
endpoint.Experiment with the various endpoints:
GET
/departments
GET
/departments/{deptNo}
GET
/employees
GET
/employees/{empNo}
GET
/sales
GET
/sales/{salesPerson}
Disconnect from the database using the
/disconnect
endpoint.For a more in-depth guide on how to setup and use the Java client, check out the dedicated documentation page here
Node.js
The Node.js sample app is a small express API which talks to IBM i. It has examples of running statements and calling simple RPGLE programs.
Setup
First step is to make sure you clone the samples repository. Inside of the samples repo is the
typescript
directory and that's where you should runnpm install
. To debug this app, we are going to use Visual Studio Code, so you can open this folder up via the command line or in VS Code itself.Environment setup
Make a copy of
.env.sample
and name it.env
. This file will be used by the VS Code debugger to determine which port to use for the APIs and which credentials to use to connect to the database. Ensure you change the variables that start withDB_
to where the Mapepir server is running.Also, if you want to make use of some sample data without your existing objects, then create this sample schema using the following SQL statement. The
SAMPLE
schema is also used in this Node.js sample.Start the app
Using the VS Code debugger, there is a 'Launch Program' option. If the app launch successfully, then you will see this in the Debug Console:
Then, you can call to the APIs that are available using your browser,
curl
, an HTTP client, etc:Notable parts of the code
In
src/index.ts
, this is where the connection pool is made and the express app is started up. The express app cannot start unless the pool is created:Here are other two important files in the TypeScript sample:
src/routes/root.ts
is where the API routes are defined and includes executing database statements.src/db/index.ts
manages the database connection pool and has methods to execute SQL statements against the database.For a more in-depth guide on how to setup and use the Node.js client, check out the dedicated documentation page here
The text was updated successfully, but these errors were encountered: