Class: DuckDB::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/duckdb/config.rb,
ext/duckdb/config.c

Overview

The DuckDB::Config encapsulates DuckDB Configuration.

require 'duckdb'
config = DuckDB::Config.new
config['default_order'] = 'DESC'
db = DuckDB::Database.open(nil, config)
con = db.connect
con.query('CREATE TABLE numbers (number INTEGER)')
con.query('INSERT INTO numbers VALUES (2), (1), (4), (3)')

# number is ordered by descending.
r = con.query('SELECT number FROM numbers ORDER BY number)
r.first.first # => 4

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject



41
42
43
44
45
46
47
48
49
50
# File 'ext/duckdb/config.c', line 41

static VALUE config_initialize(VALUE self) {
    rubyDuckDBConfig *ctx;

    TypedData_Get_Struct(self, rubyDuckDBConfig, &config_data_type, ctx);

    if (duckdb_create_config(&(ctx->config)) == DuckDBError) {
        rb_raise(eDuckDBError, "failed to create config");
    }
    return self;
}

Class Method Details

.get_config_flag(value) ⇒ Object Also known as: key_description



56
57
58
59
60
61
62
63
64
65
66
67
# File 'ext/duckdb/config.c', line 56

static VALUE config_s_get_config_flag(VALUE klass, VALUE value) {
    const char *pkey;
    const char *pdesc;

    size_t i = NUM2INT(value);

    if (duckdb_get_config_flag(i, &pkey, &pdesc) == DuckDBError) {
        rb_raise(eDuckDBError, "failed to get config information of index %ld", i);
    }

    return rb_ary_new3(2, rb_utf8_str_new_cstr(pkey), rb_utf8_str_new_cstr(pdesc));
}

.key_descriptionsObject

returns the Hash object of all available configuration names and the descriptions.

configs = DuckDB::Config.key_descriptions configs # => “The order type used when none is specified ([ASC] or DESC)”



38
39
40
41
42
43
# File 'lib/duckdb/config.rb', line 38

def key_descriptions
  @key_descriptions ||= (0...size).each_with_object({}) do |i, hash|
    key, description = key_description(i)
    hash[key] = description
  end
end

.sizeObject



52
53
54
# File 'ext/duckdb/config.c', line 52

static VALUE config_s_size(VALUE self) {
    return ULONG2NUM(duckdb_config_count());
}

Instance Method Details

#set_config(key, value) ⇒ Object Also known as: []=



69
70
71
72
73
74
75
76
77
78
79
80
# File 'ext/duckdb/config.c', line 69

static VALUE config_set_config(VALUE self, VALUE key, VALUE value) {
    const char *pkey = StringValuePtr(key);
    const char *pval = StringValuePtr(value);

    rubyDuckDBConfig *ctx;
    TypedData_Get_Struct(self, rubyDuckDBConfig, &config_data_type, ctx);

    if (duckdb_set_config(ctx->config, pkey, pval) == DuckDBError) {
        rb_raise(eDuckDBError, "failed to set config %s => %s", pkey, pval);
    }
    return self;
}