duckdb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7155944ff2739291438daed6e6f437c1ed57787ab38a5837bf28c813b8ad63ab
4
+ data.tar.gz: ac34f544906c8f089dc1c5ad1b61eb17393f09fe82d2239a4d0f6be5a9da3d70
5
+ SHA512:
6
+ metadata.gz: d194515b44611c5ea5ded32622a641e6684ef4ab4b1a4effce30dd981b225aa125457f68ce64105d0bf2f01daeb6f754c0dd6b303ebfbab58cff894900f0204c
7
+ data.tar.gz: 885ccc63e91fde398a771956f727c6b8dd2cc1bf7aa18623c24009571eed454d3d2772f4a2937b574210ed923a1ef2921a6414521bbde1ade23be97bc8f53bde
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.a
10
+ *.bak
11
+ *.bundle
12
+ *.dll
13
+ *.log
14
+ *.o
15
+ *.obj
16
+ *.so
17
+ Makefile
@@ -0,0 +1,5 @@
1
+ # ChangeLog
2
+
3
+ ## 0.0.1
4
+
5
+ - first release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in duckdb.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ duckdb (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.13.0)
10
+ rake (10.5.0)
11
+ rake-compiler (1.0.8)
12
+ rake
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 2.0)
19
+ duckdb!
20
+ minitest (~> 5.0)
21
+ rake (~> 10.0)
22
+ rake-compiler
23
+
24
+ BUNDLED WITH
25
+ 2.0.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 suketa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # ruby-duckdb
2
+
3
+
4
+ ## Description
5
+
6
+ ruby-duckdb is Ruby binding for [DuckDB](http://www.duckdb.org) database engine
7
+
8
+ ## Requirement
9
+
10
+ You must have [DuckDB](http://www.duckdb.org) engine installed in order to build/use this module.
11
+
12
+ ## How to Install
13
+
14
+ ```
15
+ gem install duckdb
16
+ ```
17
+
18
+ or you must specify the location of the include and lib files:
19
+
20
+ ```
21
+ gem install duckdb -- --with-duckdb-include=/duckdb_include_directory --with-duckdb-lib=/duckdb_library_directory
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```
27
+ require 'duckdb'
28
+
29
+ db = DuckDB::Database.open # database in memory
30
+ con = db.connect
31
+
32
+ con.query('CREATE TABLE users (id INTEGER, name VARCHAR(30))')
33
+
34
+ con.query("INSERT into users VALUES(1, 'Alice')")
35
+ con.query("INSERT into users VALUES(2, 'Bob')")
36
+ con.query("INSERT into users VALUES(3, 'Cathy')")
37
+
38
+ result = con.query('SELECT * from users')
39
+ result.each do |row|
40
+ p row
41
+ end
42
+ ```
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ require "rake/extensiontask"
11
+
12
+ task :build => :compile
13
+
14
+ Rake::ExtensionTask.new("duckdb") do |ext|
15
+ ext.lib_dir = "lib/duckdb"
16
+ end
17
+
18
+ task :default => [:clobber, :compile, :test]
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ - add test
2
+ - support prepared statement
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "duckdb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "duckdb/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "duckdb"
7
+ spec.version = Duckdb::VERSION
8
+ spec.authors = ["Masaki Suketa"]
9
+ spec.email = ["masaki.suketa@nifty.ne.jp"]
10
+
11
+ spec.summary = %q{This module is Ruby binding for DuckDB database engine.}
12
+ spec.description = %q{This module is Ruby binding for DuckDB database engine.\nYou must have the DuckDB engine installed to build/use this module.}
13
+ spec.homepage = "https://github.com/suketa/ruby-duckdb"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/suketa/ruby-duckdb"
18
+ spec.metadata["changelog_uri"] = "https://github.com/suketa/ruby-duckdb/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.require_paths = ["lib"]
26
+ spec.extensions = ["ext/duckdb/extconf.rb"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rake-compiler"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ end
@@ -0,0 +1,59 @@
1
+ #include "ruby-duckdb.h"
2
+
3
+ static VALUE cDuckDBConnection;
4
+
5
+ static void deallocate(void *ctx)
6
+ {
7
+ rubyDuckDBConnection *p = (rubyDuckDBConnection *)ctx;
8
+
9
+ duckdb_disconnect(&(p->con));
10
+ xfree(p);
11
+ }
12
+
13
+ static VALUE allocate(VALUE klass)
14
+ {
15
+ rubyDuckDBConnection *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBConnection));
16
+ return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
17
+ }
18
+
19
+ VALUE create_connection(VALUE oDuckDBDatabase) {
20
+ rubyDuckDB *ctxdb;
21
+ rubyDuckDBConnection *ctxcon;
22
+ VALUE obj;
23
+
24
+ Data_Get_Struct(oDuckDBDatabase, rubyDuckDB, ctxdb);
25
+
26
+ obj = allocate(cDuckDBConnection);
27
+ Data_Get_Struct(obj, rubyDuckDBConnection, ctxcon);
28
+
29
+ if (duckdb_connect(ctxdb->db, &(ctxcon->con)) == DuckDBError) {
30
+ rb_raise(rb_eRuntimeError, "connection error");
31
+ }
32
+
33
+ // rb_ivar_set(obj, rb_intern("database"), oDuckDBDatabase);
34
+ return obj;
35
+ }
36
+
37
+ static VALUE duckdb_connection_query(VALUE self, VALUE str) {
38
+
39
+ rubyDuckDBConnection *ctx;
40
+ rubyDuckDBResult *ctxr;
41
+
42
+ VALUE result = create_result();
43
+
44
+ Data_Get_Struct(self, rubyDuckDBConnection, ctx);
45
+ Data_Get_Struct(result, rubyDuckDBResult, ctxr);
46
+
47
+ if (duckdb_query(ctx->con, StringValueCStr(str), &(ctxr->result)) == DuckDBError) {
48
+ rb_raise(rb_eRuntimeError, "%s", ctxr->result.error_message);
49
+ }
50
+ return result;
51
+ }
52
+
53
+ void init_duckdb_connection(void)
54
+ {
55
+ cDuckDBConnection = rb_define_class_under(mDuckDB, "Connection", rb_cObject);
56
+ rb_define_alloc_func(cDuckDBConnection, allocate);
57
+
58
+ rb_define_method(cDuckDBConnection, "query", duckdb_connection_query, 1);
59
+ }
@@ -0,0 +1,13 @@
1
+ #ifndef RUBY_DUCKDB_CONNECTION_H
2
+ #define RUBY_DUCKDB_CONNECTION_H
3
+
4
+ struct _rubyDuckDBConnection {
5
+ duckdb_connection con;
6
+ };
7
+
8
+ typedef struct _rubyDuckDBConnection rubyDuckDBConnection;
9
+
10
+ void init_duckdb_connection(void);
11
+ VALUE create_connection(VALUE oDuckDBDatabase);
12
+
13
+ #endif
@@ -0,0 +1,48 @@
1
+ #include "ruby-duckdb.h"
2
+
3
+ static void deallocate(void * ctx)
4
+ {
5
+ rubyDuckDB *p = (rubyDuckDB *)ctx;
6
+
7
+ duckdb_close(&(p->db));
8
+ xfree(p);
9
+ }
10
+
11
+ static VALUE allocate(VALUE klass)
12
+ {
13
+ rubyDuckDB *ctx = xcalloc((size_t)1, sizeof(rubyDuckDB));
14
+ return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
15
+ }
16
+
17
+ static VALUE duckdb_database_s_open(int argc, VALUE *argv, VALUE cDuckDBDatabase)
18
+ {
19
+ rubyDuckDB *ctx;
20
+ VALUE obj;
21
+ char *pfile = NULL;
22
+ VALUE file = Qnil;
23
+
24
+ rb_scan_args(argc, argv, "01", &file);
25
+
26
+ if (!NIL_P(file)) {
27
+ pfile = StringValuePtr(file);
28
+ }
29
+
30
+ obj = allocate(cDuckDBDatabase);
31
+ Data_Get_Struct(obj, rubyDuckDB, ctx);
32
+ if (duckdb_open(pfile, &(ctx->db)) == DuckDBError)
33
+ {
34
+ rb_raise(rb_eRuntimeError, "Failed to open database"); /* FIXME */
35
+ }
36
+ return obj;
37
+ }
38
+
39
+ static VALUE duckdb_database_connect(VALUE self) {
40
+ return create_connection(self);
41
+ }
42
+
43
+ void init_duckdb_database(void) {
44
+ VALUE cDuckDBDatabase = rb_define_class_under(mDuckDB, "Database", rb_cObject);
45
+ rb_define_alloc_func(cDuckDBDatabase, allocate);
46
+ rb_define_singleton_method(cDuckDBDatabase, "open", duckdb_database_s_open, -1);
47
+ rb_define_method(cDuckDBDatabase, "connect", duckdb_database_connect, 0);
48
+ }
@@ -0,0 +1,12 @@
1
+ #ifndef RUBY_DUCKDB_DATABASE_H
2
+ #define RUBY_DUCKDB_DATABASE_H
3
+
4
+ struct _rubyDuckDB {
5
+ duckdb_database db;
6
+ };
7
+
8
+ typedef struct _rubyDuckDB rubyDuckDB;
9
+
10
+ void init_duckdb_database(void);
11
+
12
+ #endif
@@ -0,0 +1,12 @@
1
+ #include "ruby-duckdb.h"
2
+
3
+ VALUE mDuckDB;
4
+
5
+ void
6
+ Init_duckdb(void) {
7
+ mDuckDB = rb_define_module("DuckDB");
8
+
9
+ init_duckdb_database();
10
+ init_duckdb_connection();
11
+ init_duckdb_result();
12
+ }
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+
3
+ dir_config('duckdb')
4
+ have_library('duckdb')
5
+ create_makefile('duckdb')
@@ -0,0 +1,54 @@
1
+ #include "ruby-duckdb.h"
2
+
3
+ static VALUE cDuckDBResult;
4
+
5
+ static void deallocate(void *ctx)
6
+ {
7
+ rubyDuckDBResult *p = (rubyDuckDBResult *)ctx;
8
+
9
+ duckdb_destroy_result(&(p->result));
10
+ xfree(p);
11
+ }
12
+
13
+ static VALUE allocate(VALUE klass)
14
+ {
15
+ rubyDuckDBResult *ctx = xcalloc((size_t)1, sizeof(rubyDuckDBResult));
16
+ return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
17
+ }
18
+
19
+ static VALUE row_array(rubyDuckDBResult *ctx, size_t row_idx) {
20
+ size_t col_idx;
21
+ VALUE ary = rb_ary_new2(ctx->result.column_count);
22
+ for(col_idx = 0; col_idx < ctx->result.column_count; col_idx++) {
23
+ char *p = duckdb_value_varchar(&(ctx->result), col_idx, row_idx);
24
+ rb_ary_store(ary, col_idx, rb_str_new2(p));
25
+
26
+ free(p);
27
+ }
28
+ return ary;
29
+ }
30
+
31
+ static VALUE duckdb_result_each(VALUE oDuckDBResult) {
32
+ rubyDuckDBResult *ctx;
33
+ size_t row_idx = 0;
34
+
35
+ // RETURN_ENUMERATOR(oDuckDBResult, 0, 0);
36
+
37
+ Data_Get_Struct(oDuckDBResult, rubyDuckDBResult, ctx);
38
+ for (row_idx = 0; row_idx < ctx->result.row_count; row_idx++) {
39
+ rb_yield(row_array(ctx, row_idx));
40
+ }
41
+ return oDuckDBResult;
42
+ }
43
+
44
+ VALUE create_result(void) {
45
+ return allocate(cDuckDBResult);
46
+ }
47
+
48
+ void init_duckdb_result(void)
49
+ {
50
+ cDuckDBResult = rb_define_class_under(mDuckDB, "Result", rb_cObject);
51
+ rb_define_alloc_func(cDuckDBResult, allocate);
52
+
53
+ rb_define_method(cDuckDBResult, "each", duckdb_result_each, 0);
54
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef RUBY_DUCKDB_RESULT_H
2
+ #define RUBY_DUCKDB_RESULT_H
3
+
4
+ struct _rubyDuckDBResult {
5
+ duckdb_result result;
6
+ };
7
+
8
+ typedef struct _rubyDuckDBResult rubyDuckDBResult;
9
+
10
+ void init_duckdb_result(void);
11
+ VALUE create_result(void);
12
+
13
+ #endif
14
+
@@ -0,0 +1,12 @@
1
+ #ifndef RUBY_DUCKDB_H
2
+ #define RUBY_DUCKDB_H
3
+
4
+ #include "ruby.h"
5
+ #include <duckdb.h>
6
+ #include "./database.h"
7
+ #include "./connection.h"
8
+ #include "./result.h"
9
+
10
+ extern VALUE mDuckDB;
11
+
12
+ #endif
@@ -0,0 +1,5 @@
1
+ require "duckdb/version"
2
+ require "duckdb/duckdb"
3
+
4
+ module Duckdb
5
+ end
@@ -0,0 +1,3 @@
1
+ module Duckdb
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: duckdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masaki Suketa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: This module is Ruby binding for DuckDB database engine.\nYou must have
70
+ the DuckDB engine installed to build/use this module.
71
+ email:
72
+ - masaki.suketa@nifty.ne.jp
73
+ executables: []
74
+ extensions:
75
+ - ext/duckdb/extconf.rb
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - TODO
86
+ - bin/console
87
+ - bin/setup
88
+ - duckdb.gemspec
89
+ - ext/duckdb/connection.c
90
+ - ext/duckdb/connection.h
91
+ - ext/duckdb/database.c
92
+ - ext/duckdb/database.h
93
+ - ext/duckdb/duckdb.c
94
+ - ext/duckdb/extconf.rb
95
+ - ext/duckdb/result.c
96
+ - ext/duckdb/result.h
97
+ - ext/duckdb/ruby-duckdb.h
98
+ - lib/duckdb.rb
99
+ - lib/duckdb/version.rb
100
+ homepage: https://github.com/suketa/ruby-duckdb
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ homepage_uri: https://github.com/suketa/ruby-duckdb
105
+ source_code_uri: https://github.com/suketa/ruby-duckdb
106
+ changelog_uri: https://github.com/suketa/ruby-duckdb/CHANGELOG.md
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.0.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: This module is Ruby binding for DuckDB database engine.
126
+ test_files: []