Skip to content
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

Why writing a database driver is hard #48

Open
worksofliam opened this issue Jan 21, 2021 · 0 comments
Open

Why writing a database driver is hard #48

worksofliam opened this issue Jan 21, 2021 · 0 comments

Comments

@worksofliam
Copy link
Owner

For the longest time, I had wanted a native Node.js database driver for Db2 for i. This meant writing the entire socket connection in JavaScript, using net.Socket, Buffer, and other things. There is no documentation on the Db2 for i socket server, other than existing code bases like jtopen.

As a suggestion from ThePrez himself, I actually used the codebase for jtopenlite as it was more precise in what I was trying to do (e.g. not recreate the entirety of jtopen, but just the database portion of it). jtopenlite was a great guide for me getting started.

Creating the connection to the database was generally a lot of work. I got it working to the point where it was creating an 'authentication job', which we can see from this image.

image

Since the process of creating a valid database connection is messy, I ended up creating this document to outline the flow of how the connection should be made to Db2 for i. As you can probably tell.. there are a lot of steps. Sad times indeed.

There are two separate connections when connecting to the database:

  1. One to authenticate and start the database job.
  2. One that connects to the database job that was spun up.

After you've got the main connection, you need to set all the connection attributes.

image
image
image

Some key recorded moments of development:

The issue with this project

The issue with this project is that it's so big. It's really a lot of work for a one-person job who is only doing it in their spare time. There is too much to implement and just not enough time in the day. These were some of the things that make this project so big

  • Different SQL data type implementation
  • Binding parameters in queries
  • Calling stored procedures (with IN, OUT, INOUT support)
  • Supporting (too) many CCSIDs
  • Writing a nice API
  • Connection pools
  • Documenting the socket connection

As much as I would love to continue working on it, I personally don't have a lot of time. This dream will live on. This is as far as I got with the API:

const connection = require('./lib/driver/Connection');

(async () => {
  const conn = await connection.getConnection(false, process.env.SYSTEM, process.env.USER, process.env.PASS);

  const stmt = await conn.createStatement();

  conn.close();
})();

You can find the repository here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant