如何在go中连接Oracle [英] How to connect to Oracle in go

查看:267
本文介绍了如何在go中连接Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收集有两种方法可以连接到Oracle数据库(在Windows上):


  1. github.com/tgulacsi/goracle

  2. github.com/mattn/go-oci8

但是对于我这个级别的人这两个方法/驱动程序非常棘手。



这也是一个负担,必须经历所有这些才能部署,在不同的机器上开发等等(还假设它会起作用)。

有没有更好的方法连接到golang中的Oracle数据库,或者如果没有人能够在高层次视图或任何视图中向我解释,让这更容易?



指针将非常感谢。



TQ。

$ b $如果您仍然对我感兴趣,我已经在Windows上使用Go和Oracle几个月了。到目前为止,我最喜欢的车手是go-oci8。它比goracle快得多,似乎更加活跃。



我们的一些应用程序需要部署在我们无法访问的计算机上。这两种本地SQL驱动程序都可以在不需要任何外部配置的情况下与应用程序一起编译,因此这是一个巨大的优势计算机仍然需要安装Oracle客户端,但这是唯一的外部依赖。



我不会说go-oci8是生产准备好的,但它足够稳定你知道它的局限性。一个例子是,它在同时运行多个goroutine时会发生混乱,所以如果你需要这个,你可能想使用一个互斥体。



我基本上遵循这个教程来安装它: https://gist.github.com/mnadel/8678269



最棘手的部分是正确创建oci8.pc。我的是:

  prefix = / devel / target / 1.0 
exec_prefix = $ {prefix}
libdir C:/ oracle / instantclient_12_1_64 / sdk / lib / msvc
includedir = C: b orainclude = C:/ oracle / instantclient_12_1_64 / sdk / include
gcclib = c:/ MinGW_64 / mingw64 / lib
gccinclude = c:/ MinGW_64 / mingw64 / lib
glib_genmarshal = glib-genmarshal
gobject_query = gobject-query
glib_mkenums = glib-mkenums
名称:oci8
版本:12.1
描述:oci8库
Libs:-L $ { oralib} -L $ {gcclib} -loci
Libs.private:
Cflags:-I $ {orainclude} -I $ {gccinclude}

有些东西可能会减少,我可能会试着在一台干净的机器上改进它。



一件重要的事情要记住的是,您应该为Go和Oracle客户端使用相同的体系结构。所以如果你想使用64位版本的Go,你还需要64位版本的Oracle。我有32位和64位两种版本,而64位是我的默认版本,当我需要构建32位版本时,我使用bat文件来更改必要的路径和环境变量。



可能需要投入一些时间才能使其工作,您可能会获得比使用ODBC更好的性能。我一直在使用它的数据量较高(查询可获取500万行以上),并且效果非常好。


I gather there are two ways to connect to Oracle DB in Go (on windows):

  1. github.com/tgulacsi/goracle
  2. github.com/mattn/go-oci8

But for someone of my level (beginner in open source+golang), those two methods/drivers are awfully tricky.

It's also a burden having to go through all of that for deployment, development on different machines etc. (Also assuming it will work).

Is there a better way to connect to Oracle db in golang or if there is not then can someone explain to me in high level view or any view for that matter that would make this easier?

Pointers would be very much appreciated.

TQ.

解决方案

If you are still interested, I have been working with Go and Oracle on Windows for a few months now. My favorite driver so far is go-oci8. It is much faster than goracle and seems to be more active.

Some of our applications need to be deployed on computers that we don't have access to. Both native SQL drivers are compiled with the application without the need for any external configuration, so that is a huge plus. The computer will still need Oracle client installed, but that is the only external dependency.

I won't say go-oci8 is production ready yet, but it's stable enough when you know its limitations. One example is that it panics when running on multiple goroutines simultaneously, so if you need that you might want to use a mutex.

I have basically followed this tutorial to install it: https://gist.github.com/mnadel/8678269

The trickiest part was creating oci8.pc corretly. Mine is:

prefix=/devel/target/1.0
exec_prefix=${prefix}
libdir=C:/oracle/instantclient_12_1_64/sdk/lib/msvc
includedir=C:/oracle/instantclient_12_1_64/sdk/include
oralib=C:/oracle/instantclient_12_1_64/sdk/lib/msvc
orainclude=C:/oracle/instantclient_12_1_64/sdk/include
gcclib=c:/MinGW_64/mingw64/lib
gccinclude=c:/MinGW_64/mingw64/lib
glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums
Name: oci8
Version: 12.1
Description: oci8 library
Libs: -L${oralib} -L${gcclib} -loci
Libs.private:
Cflags: -I${orainclude} -I${gccinclude}

Some things might be reduntant, I might try to improve it on a clean machine.

An important thing to have in mind is that you should use the same architecture for Go and the Oracle client. So if you want to use the 64 bit version of Go you will also need the 64 bit version of Oracle. I have both 32 and 64 bit versions of both, and while 64 bit is my default I use bat files to change the necessary paths and environment variables when I need to build a 32 bit version.

It might be worth investing some time to make it work, you will probably get much better performance than using ODBC. I have been using it with somewhat high data volume (queries that fetch 5+ million rows) and it works very well.

这篇关于如何在go中连接Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆