All Projects → babashka → babashka-sql-pods

babashka / babashka-sql-pods

Licence: EPL-1.0 license
Babashka pods for SQL databases

Programming Languages

clojure
4091 projects
shell
77523 projects

Projects that are alternatives of or similar to babashka-sql-pods

doc
QuickPerf documentation: https://github.com/quick-perf/doc/wiki/QuickPerf
Stars: ✭ 22 (-65.62%)
Mutual labels:  jdbc
metadata
oracle,mysql,sql server 元数据管理表生成
Stars: ✭ 45 (-29.69%)
Mutual labels:  jdbc
neo4j-jdbc
JDBC driver for Neo4j
Stars: ✭ 110 (+71.88%)
Mutual labels:  jdbc
couchbase-java-importer
This is a pluggable importer for Couchbase
Stars: ✭ 13 (-79.69%)
Mutual labels:  jdbc
kotlin-coroutines-jdbc
A library for interacting with blocking JDBC drivers using Kotlin Coroutines.
Stars: ✭ 40 (-37.5%)
Mutual labels:  jdbc
facilejdbc
FacileJDBC - Fast, simple and lightweight JDBC wrapper
Stars: ✭ 34 (-46.87%)
Mutual labels:  jdbc
Hikaricp
光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Stars: ✭ 16,146 (+25128.13%)
Mutual labels:  jdbc
nifi-sqllookup-services-bundle
NIFI controllers for SQL record and attributes lookups with built-in caching
Stars: ✭ 18 (-71.87%)
Mutual labels:  jdbc
kylin-jdbc-pool
better performance for kylin query
Stars: ✭ 15 (-76.56%)
Mutual labels:  jdbc
ksql-jdbc-driver
JDBC driver for Apache Kafka
Stars: ✭ 85 (+32.81%)
Mutual labels:  jdbc
holy-lambda
The extraordinary simple, performant, and extensible custom AWS Lambda runtime for Clojure.
Stars: ✭ 318 (+396.88%)
Mutual labels:  babashka
corona cases
🦠 Coronavirus Information on Telegram Chatbot
Stars: ✭ 19 (-70.31%)
Mutual labels:  babashka
shoppingPro
此项目是橘子网上商城的功能,按照我自己的想法实现的一个自营模式的商城应用。 目前实现了前台的功能,后台的功能,主要有登录,注册,商品展示,购物车等模块。后台面有添加商品,删除商品,商品上下架,订单管理,管理员管理,实现了E支付功能和百度地图功能.为了便于此项目日后的完善和扩展, 我采用了前后端分离的架构设计。前端主要使用javaScript,jquery,AjAX,JSP构建的单页web应用, 通过使用指令,服务,模板,控制器完成前端的MVC分层,各个模板页面的效果实现则使用了基本的CSS3等技术, 结合JS完成页面的基本交互效果。由于有实现数据库和后台模块等功能,通过AJax请求完成整个前台功能的数据交互, 后期再考虑实现一个后台管理系统及数据库系统,还有前端页面资源的异步加载及优化。
Stars: ✭ 28 (-56.25%)
Mutual labels:  jdbc
AWR.Athena
Short R Wrapper for Athena JDBC connections
Stars: ✭ 23 (-64.06%)
Mutual labels:  jdbc
blade-jdbc
🐜 move to https://github.com/biezhi/anima
Stars: ✭ 36 (-43.75%)
Mutual labels:  jdbc
MiniDao
An powerful enhanced toolkit of SpringJdbc for simplify development
Stars: ✭ 200 (+212.5%)
Mutual labels:  jdbc
aws-postgresql-jdbc
Note: The Amazon Web Services (AWS) JDBC Driver for PostgreSQL project has moved to a new repository. Visit us at our new repository for the latest version and information (link below). The Amazon Web Services (AWS) JDBC Driver for PostgresSQL is a driver that enables applications to take full advantage of the features of clustered PostgreSQL da…
Stars: ✭ 69 (+7.81%)
Mutual labels:  jdbc
apache-flink-jdbc-streaming
Sample project for Apache Flink with Streaming Engine and JDBC Sink
Stars: ✭ 22 (-65.62%)
Mutual labels:  jdbc
ThinkJD
ThinkJD,又名ThinkJDBC,一个简洁而强大的开源JDBC操作库。你可以使用Java像ThinkPHP框架的M方法一样,一行代码搞定数据库操作。ThinkJD, also known as ThinkJDBC, an easy and powerful open source JDBC library. You can operate the database with one line of Java code,just like the M method of ThinkPHP framework.
Stars: ✭ 24 (-62.5%)
Mutual labels:  jdbc
hasor
Hasor是一套基于 Java 语言的开发框架,区别于其它框架的是 Hasor 有着自己一套完整的体系,同时还可以和先有技术体系做到完美融合。它包含:IoC/Aop容器框架、Web框架、Jdbc框架、RSF分布式RPC框架、DataQL引擎,等几块。
Stars: ✭ 938 (+1365.63%)
Mutual labels:  jdbc

Babashka sql pods

Babashka pods for interacting with SQL databases.

Supported databases:

PRs for other SQL databases are welcome. (Look at #15 + #20 for an example of adding a new DB.)

Install

The following installation methods are available:

  • Use the latest version from the pod-registry. This is done by calling load-pod with a qualified keyword:

    (require '[babashka.pods :as pods])
    (pods/load-pod 'org.babashka/postgresql "0.1.0")

    Babashka will automatically download the pod if it is not available on your system yet.

  • Download a binary from Github releases

Compatibility

Pods from this repo require babashka v0.4.3 or later.

Available vars

The pods expose these namespaces with vars, where <db> must be substituted with the database type, either hsqldb, postgresql, or oracle:

  • pod.babashka.<db>:
    • execute!: similar to next.jdbc/execute!
    • execute-one!: similar to next.jdbc/execute-one!
    • get-connection: returns connection serialized using maps with a unique identifier key
    • close-connection: closes a connection returned from get-connection
    • with-transaction: similar to next.jdbc/with-transaction
  • pod.babashka.<db>.sql:
    • insert-multi!: similar to next.jdbc.sql/insert-multi!
  • pod.babashka.<db>.transaction:
    • begin: marks the begin of a transaction, expects connection returned from get-connection
    • rollback: rolls back transaction, expects connection returned from get-connection
    • commit: commits transaction, expects connection returned from get-connection

More functions from next.jdbc can be added. PRs welcome.

Run

An example using pod-babashka-postgresql:

(require '[babashka.pods :as pods])

;; load from pod registry:
(pods/load-pod 'org.babashka/postgresql "0.1.0")
;; or load from system path:
;; (pods/load-pod "pod-babashka-postgresql")
;; or load from a relative or absolute path:
;; (pods/load-pod "./pod-babashka-postgresql")

(require '[pod.babashka.postgresql :as pg])

(def db {:dbtype   "postgresql"
         :host     "your-db-host-name"
         :dbname   "your-db"
         :user     "develop"
         :password "develop"
         :port     5432})

(pg/execute! db ["select version()"])
;;=> [{:version "PostgreSQL 9.5.18 on x86_64-pc-linux-gnu (Debian 9.5.18-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit"}]

An example using pod-babashka-hsqldb:

(require '[babashka.pods :as pods])

;; load from pod registry:
(pods/load-pod 'org.babashka/hsqldb "0.1.0")
;; or load from system path:
;; (pods/load-pod "pod-babashka-hsqldb")
;; or load from a relative or absolute path:
;; (pods/load-pod "./pod-babashka-hsqldb")

(require '[pod.babashka.hsqldb :as db])

(def db "jdbc:hsqldb:mem:testdb;sql.syntax_mys=true")
(db/execute! db ["create table foo ( foo int );"])
;;=> [#:next.jdbc{:update-count 0}]

(db/execute! db ["create table foo ( foo int );"])
;;=> ... error output from pod omitted
;;=> clojure.lang.ExceptionInfo: object name already exists: FOO in statement [create table foo ( foo int )] [at line 6, column 1]

(db/execute! db ["insert into foo values (1, 2, 3);"])
;;=> [#:next.jdbc{:update-count 3}]

(db/execute! db ["select * from foo;"])
;;=> [#:FOO{:FOO 1} #:FOO{:FOO 2} #:FOO{:FOO 3}]

A more elaborate example can be found here.

Arrays

Writing arrays

Inserting arrays works automatically: just pass a Java array, with e.g. (into-array [1 2 3]).

Reading arrays

Array columns automatically get converted to Clojure vectors. Converting back into arrays must be done manually.

JSON

This section only applies to PostgreSQL for now, but can be extended to other databases.

Writing JSON

  • Convert to a JSON string manually and insert with ?::text. PostgreSQL will automatically convert the parameter to the right type. Full example:
(db/execute! db ["insert into json_table values (?::text);" (json/generate-string {:a 1})])
  • Use db/write-json or db/write-jsonb. Full example:
(db/execute! db ["insert into json_table values (?);" (db/write-json {:a 1})])

Reading JSON

  • Both json and jsonb are automatically converted to Clojure values. Keys are keywordized automatically. You can override this behavior by passing a :pod.babashka.sql/read option to execute!:
{:pod.babashka.sql/read {:json :parse+keywordize}} ;; default
{:pod.babashka.sql/read {:json :parse}} ;; no keyword keys
{:pod.babashka.sql/read {:json :string}} ;; json as raw string

Use :jsonb to apply these options to jsonb-typed columns.

  • Select column as text and deserialize the result manually:
(db/execute! db ["select json::text from json_table;"])

Libraries

In addition to using a sql pod, the following babashka-compatible libraries might be helpful:

honeysql

Turn Clojure data structures into SQL.

Needs babashka >= 0.2.6. Babashka is tested against HoneySQL version 2.2.861 in CI.

Example:

(ns honeysql-script
  (:require [babashka.deps :as deps]
            [babashka.pods :as pods]))

;; Load HoneySQL from Clojars:
(deps/add-deps '{:deps {com.github.seancorfield/honeysql {:mvn/version "2.2.861"}}})

(require '[honey.sql :as hsql])

(hsql/format {:select [:a :b :c] :from [:foo] :where [:= :a 1]})
;;=> ["SELECT a, b, c FROM foo WHERE a = ?" 1]

Troubleshooting

MS SQL Server support

If you are connecting to SQL Server, you may try connecting like this:

(require '[pod.babashka.mssql :as sql])
(def db {:dbtype "mssql" :host "my-dbhost" :dbname "my_db" :integratedSecurity true})
(sql/execute! db ...)

Using integrated security like this will not work (yet?) - you will get an error:

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  This driver is not configured for integrated authentication. ClientConnectionId:889ad681-4fdf-409c-b12c-9eef93129023

As a workaround, you can use this pod, which connects via a .NET library.

If you are using SQL Server, you may also be interested in this pod, which has a function to reformat/indent your SQL.

Dev

Set POD_DB_TYPE to either hsqldb, postgresql, or oracle.

Build

Run script/compile

Test

Run script/test.

License

Copyright © 2020-2021 Michiel Borkent

Distributed under the EPL License. See LICENSE.

Helidon license HyperSQL license MySQL JDBC license MSSQL JDBC license PostgreSQL JDBC license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].