DBAPIs and psycopg2

We will sometimes want to interact with our database and use its results in a specific programming language. E.g. to build web applications or data pipelines in a specific language (Ruby, Python, Javascript, etc.) That’s where DBAPIs come in.

  • A DBAPI
    • provides a standard interface for one programming language (like Python) to talk to a relational database server.
    • is a low level library for writing SQL statements that connect to a database
    • is also known as database adapters
  • Different DBAPIs exist for every server framework or language + database system
  • Database adapters define a standard for using a database (with SQL) and using the results of database queries as input data in the given language.
    • Turn a selected SELECT * FROM some_table; list of rows into an array of objects in Javascript for say a NodeJS adapter; or a list of tuples in Python for a Python adapter.

Example across languages and server frameworks

  • For Ruby (e.g. for Sinatra, Ruby on Rails): pg
  • For NodeJS: node-postgres
  • For Python (e.g. for Flask, Django): pyscopg2

Guess you like

Origin blog.csdn.net/BSCHN123/article/details/121188420