Git Product home page Git Product logo

libpq's Introduction

libpq

libpq provides a libpq foreign function interface (FFI) for Scala Native. A Scala Native application can link (using LLD) with a C library but the C functions that it needs to use from that library have to be declared in a particular way. Additionally, a good FFI should provide another layer around the basic C function bindings that allows those functions to be used in a way that only requires knowledge of the Scala programming language and does not require any knowledge of C.

To use this library for application development, you only need to import from io.github.edadma.libpq, and not from the subpackage extern which provides the raw C library bindings for internal use only.

The following example program performes a database query to find out Bob's last name.

package io.github.edadma.libpq

@main def run(): Unit =
  val conn = connectDB("dbname=<database name> user=<user name> password=<user password> host=<hostname>")

  if conn.status == ConnStatus.BAD then
    println(s"connection failed ${conn.errorMessage}")
    conn.finish()
    sys.exit(1)

  val res = conn.exec("SELECT lastname FROM users WHERE email='[email protected]'")

  if res.status != ExecStatus.TUPLES_OK then
    println("no data")
    res.clear()
    conn.finish()
    sys.exit(1)

  val rows = res.nTuples

  for i <- 0 until rows do println(s"${res.getValue(i, 0)}")

  res.clear()
  conn.finish()

libpq's People

Contributors

edadma avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.