Open worksofliam opened 2 weeks ago
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?
java.net.UnknownHostException: hiddenthename.COM: hiddenthename.COM: Hostname and service name not provided or found at java.net.InetAddress.getLocalHost(InetAddress.java:1685) at com.github.ibm.mapepire.certstuff.SelfSignedCertGenerator.generate(SelfSignedCertGenerator.java:24) at com.github.ibm.mapepire.certstuff.ServerCertGetter.get(ServerCertGetter.java:102) at com.github.ibm.mapepire.MapepireServer.main(MapepireServer.java:74) Caused by: java.net.UnknownHostException: hiddenthename.COM: Hostname and service name not provided or found at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:1048) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1462) at java.net.InetAddress.getLocalHost(InetAddress.java:1680) ... 3 more
@GajenderI please raise your issue in the Mapepire-server repo. Thanks!
Will this be the ultimate and only ODBC driver from IBM and get regular updates?
@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.
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
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 ```sh pip install mapepire-python ``` 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: ```ini [mapepire] SERVER="SERVER" PORT="PORT" USER="USER" PASSWORD="PASSWORD" ``` The following script sets up a `DaemonServer` object that will be used to connect with the Server Component. Then a single `SQLJob` is created to facilitate the connection from the client side. ```python import configparser from mapepire_python.client.sql_job import SQLJob from mapepire_python.data_types import DaemonServer config = configparser.ConfigParser() config.read('mapepire.ini') creds = DaemonServer( host=config['mapepire']['SERVER'], port=config['mapepire']['PORT'], user=config['mapepire']['USER'], password=config['mapepire']['PASSWORD'], ignoreUnauthorized=True ) with SQLJob(creds) as sql_job: with sql_job.query("select * from sample.employee") as query: result = query.run(rows_to_fetch=1) print(result['data']) ``` Here is the output from the script above: ```sh { "EMPNO":"000010", "FIRSTNME":"CHRISTINE", "MIDINIT":"I", "LASTNAME":"HAAS", "WORKDEPT":"A00", "PHONENO":"3978", "HIREDATE":"01/01/65", "JOB":"PRES", "EDLEVEL":18, "SEX":"F", "BIRTHDATE":"None", "SALARY":52750.0, "BONUS":1000.0, "COMM":4220.0 } ``` For more in depth usage, refer to the Python Client docs: - [docs](https://mapepire-ibmi.github.io/guides/usage/python/) - [github](https://github.com/Mapepire-IBMi/mapepire-python) - [sample notebook](https://github.com/Mapepire-IBMi/samples/tree/main/python)Java
Getting started with the Java client (`mapepire-sdk`) is as easy adding a `maven` dependency in your project: ```xmlNode.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](https://github.com/Mapepire-IBMi/samples). Inside of the samples repo is the `typescript` directory and that's where you should run `npm 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. ```sh git clone https://github.com/Mapepire-IBMi/samples.git cd samples/typescript npm i code . ``` #### 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 with `DB_` to where the Mapepir server is running. ```sh PORT=3000 DB_HOST=hostname DB_ID=userprofile DB_PASSWORD=x ``` 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. ```sql QSYS.CREATE_SQL_SAMPLE('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: ``` /Users/barry/.nvm/versions/node/v20.14.0/bin/node ./build/index.js Example app listening on port 3000 ``` Then, you can call to the APIs that are available using your browser, `curl`, an HTTP client, etc: ``` barry@Liams-MBP typescript % curl localhost:3000 Hello world! barry@Liams-MBP typescript % curl localhost:3000/test [{"EMPNO":"000010","FIRSTNME":"CHRISTINE","MIDINIT":"I","LAST... ``` #### 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: ```ts db.connect(DatabaseServer).then(() => { app.listen(port, () => { console.log(`Example app listening on port ${port}`) }); }); ``` 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](https://mapepire-ibmi.github.io/guides/usage/nodejs/)