@naxmefy/jdbc
use jdbc from node
Last updated 2 months ago by naxmefy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @naxmefy/jdbc 
SYNC missed versions from official npm registry.

@naxmefy/jdbc

small wrapper to work with jdbc in node.

npm version

Build Status Coverage Status

prerequisites

node-java

$ npm install --save java

HINT

node-java installation can fail on windows (i never got it work on windows).

I used docker on windows to get it working.

You can find my example docker image on docker hub at https://hub.docker.com/r/naxmefy/node-java/ or https://github.com/naxmefy/docker-node-java

OPTIONAL: node-java-maven

$ npm install --save node-java-maven

installation

$ npm install --save @naxmefy/jdbc

usage

setup jdbc driver inside package.json

{
    "name": "myapp",
    "version": "0.0.0",
    "private": true,
    "java": {
      "dependencies": [
        {
          "groupId": "com.h2database",
          "artifactId": "h2",
          "version": "1.4.195"
        }
      ]
    },
    "dependencies": {
      "@naxmefy/jdbc": "^0.1.0",
      "java": "^0.8.0",
      "node-java-maven": "^0.0.12"
    }
}

in your main file (js)

const JDBC = require('@naxmefy/jdbc').JDBC
const myDatabase = new JDBC({
  className: 'any.jdbc.Driver',
  url: 'jdbc:to:any.db',
  username: 'foo',
  password: 'bar'
})

myDatabase.createStatement()
  .then(statement => {
    return statement.executeQuery('SELECT * FROM FOO')
  })
  .then(resultSet => {
      const arrayOfResults = resultSet.fetchAllResults()
      arrayOfResults.forEach(result => {
          console.log(result)
      })
  })

or with typescript (types included)

import {JDBC, ResultSet, Statement} from '@naxmefy/jdbc'
const myDatabase = new JDBC({
  className: 'any.jdbc.Driver',
  url: 'jdbc:to:any.db',
  username: 'foo',
  password: 'bar'
})

myDatabase.createStatement()
  .then((statement: Statement) => {
    return statement.executeQuery('SELECT * FROM FOO')
  })
  .then((resultSet: ResultSet) => {
      const arrayOfResults = resultSet.fetchAllResults()
      arrayOfResults.forEach(result => {
          console.log(result)
      })
  })

usage with Docker

HINT

The following docker config contains proxy config too. Maybe you do not need it.

example Dockerfile

FROM naxmefy/node-java

WORKDIR /usr/app

COPY package.json .
RUN npm config set proxy $HTTP_PROXY
RUN npm config set https-proxy $HTTPS_PROXY
RUN npm install --quiet

COPY . .

example docker-compose.yml

version: '2'
services:
  web:
    build:
      context: .
      args:
        - http_proxy
        - https_proxy
        - no_proxy
        - HTTP_PROXY
        - HTTPS_PROXY
        - NO_PROXY
    command: npm start
    volumes:
      - .:/usr/app/
      - /usr/app/node_modules
    ports:
      - "3000:3000"
    links:
      - postgres
    environment:
      NODE_ENV: development
      DEBUG: @naxmefy/jdbc
  postgres:
    image: postgres
    environment:
      POSTGRES_USER: pguser
      POSTGRES_PASSWORD: pgpass
      POSTGRES_DB: pgdb
    ports:
      - "5432:5432"

example java maven config

{
  "java": {
    "dependencies": [
      {
        "groupId": "org.postgresql",
        "artifactId": "postgresql",
        "version": "42.1.1"
      }
    ]
  }
}

example jdbc instantiation

const myPostgresDB = new JDBC({
  className: 'org.postgresql.Driver',
  url: 'jdbc:postgresql://postgres:5432/pgdb',
  username: 'pguser',
  password: 'pgpass'
})

Contributing

  • open issues for bugs or whatever
  • fork repo, make change, start pull request

License

MIT

Current Tags

  • 0.13.0                                ...           latest (2 months ago)

15 Versions

  • 0.13.0                                ...           2 months ago
  • 0.12.0                                ...           a year ago
  • 0.11.0                                ...           a year ago
  • 0.10.1                                ...           a year ago
  • 0.9.0                                ...           3 years ago
  • 0.8.0                                ...           3 years ago
  • 0.7.2                                ...           3 years ago
  • 0.6.2                                ...           4 years ago
  • 0.6.1                                ...           4 years ago
  • 0.6.0                                ...           4 years ago
  • 0.5.0                                ...           4 years ago
  • 0.4.0 [deprecated]           ...           4 years ago
  • 0.3.0 [deprecated]           ...           4 years ago
  • 0.2.0 [deprecated]           ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 0
Last Day 0
Last Week 0
Last Month 16
Dependencies (10)
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |