ruby-ladybug 0.1.0
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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/History.md +9 -0
- data/LICENSE.txt +20 -0
- data/README.md +250 -0
- data/ext/ladybug_ext/config.c +318 -0
- data/ext/ladybug_ext/connection.c +331 -0
- data/ext/ladybug_ext/database.c +197 -0
- data/ext/ladybug_ext/extconf.rb +20 -0
- data/ext/ladybug_ext/ladybug_ext.c +158 -0
- data/ext/ladybug_ext/ladybug_ext.h +132 -0
- data/ext/ladybug_ext/node.c +24 -0
- data/ext/ladybug_ext/prepared_statement.c +396 -0
- data/ext/ladybug_ext/query_summary.c +140 -0
- data/ext/ladybug_ext/recursive_rel.c +24 -0
- data/ext/ladybug_ext/rel.c +24 -0
- data/ext/ladybug_ext/result.c +514 -0
- data/ext/ladybug_ext/types.c +619 -0
- data/lib/ladybug/config.rb +70 -0
- data/lib/ladybug/connection.rb +51 -0
- data/lib/ladybug/database.rb +53 -0
- data/lib/ladybug/node.rb +46 -0
- data/lib/ladybug/prepared_statement.rb +44 -0
- data/lib/ladybug/query_summary.rb +28 -0
- data/lib/ladybug/recursive_rel.rb +37 -0
- data/lib/ladybug/rel.rb +57 -0
- data/lib/ladybug/result.rb +196 -0
- data/lib/ladybug.rb +89 -0
- data/spec/ladybug/config_spec.rb +98 -0
- data/spec/ladybug/connection_spec.rb +36 -0
- data/spec/ladybug/database_spec.rb +57 -0
- data/spec/ladybug/prepared_statement_spec.rb +91 -0
- data/spec/ladybug/query_summary_spec.rb +30 -0
- data/spec/ladybug/result_spec.rb +225 -0
- data/spec/ladybug/types_spec.rb +285 -0
- data/spec/ladybug_spec.rb +83 -0
- data/spec/spec_helper.rb +101 -0
- data.tar.gz.sig +0 -0
- metadata +177 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7b1d33c54dd9d7ffa7c488fcbab32b251daf549ca772d3190a19bca475b17c84
|
|
4
|
+
data.tar.gz: 5c74689b9bbcff42b6c3c2a9bf0e89dbafab675966bf91c1a4326bc2231434c6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 67f33c1849dbe93cf15b0a6df16a8d232ce27319a570aa7fbbbcad3382fbffe0fee40e71984a9d5df63fa0df238826f2aefcd60e984611ec8d85609019511cb5
|
|
7
|
+
data.tar.gz: b1e8e192ed387249a6cf5a823caa2a4614ddbc0efbc06ab76de35ff48098b655a132739bda4b30b2f8fc9baab8623696f35b2ad16076eafe773e344574e5e345
|
checksums.yaml.gz.sig
ADDED
|
Binary file
|
data/History.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2025 Michael Granger
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# ruby-ladybug
|
|
2
|
+
|
|
3
|
+
home
|
|
4
|
+
: https://sr.ht/~ged/Ruby-Ladybug
|
|
5
|
+
|
|
6
|
+
code
|
|
7
|
+
: https://hg.sr.ht/~ged/Ruby-Ladybug
|
|
8
|
+
|
|
9
|
+
github
|
|
10
|
+
: https://github.com/ged/ruby-ladybug
|
|
11
|
+
|
|
12
|
+
docs
|
|
13
|
+
: https://deveiate.org/code/ruby-ladybug
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Description
|
|
17
|
+
|
|
18
|
+
A Ruby binding for the [LadybugDB](https://ladybugdb.com) embedded graph database.
|
|
19
|
+
|
|
20
|
+
[](https://builds.sr.ht/~ged/Ruby-Ladybug?)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Creating A Database and Connecting To It
|
|
24
|
+
|
|
25
|
+
To create an in-memory database:
|
|
26
|
+
|
|
27
|
+
database = Ladybug.database
|
|
28
|
+
# => #<Ladybug::Database:0x000000012917ec68 path:nil read-only:false>
|
|
29
|
+
|
|
30
|
+
Or explicitly via an empty string:
|
|
31
|
+
|
|
32
|
+
database = Ladybug.database( '' )
|
|
33
|
+
# => #<Ladybug::Database:0x000000012144edb0 path:nil read-only:false>
|
|
34
|
+
|
|
35
|
+
If you pass a non-empty string, it is assumed to be the path to a database:
|
|
36
|
+
|
|
37
|
+
database = Ladybug.database( 'path/to/mydb' )
|
|
38
|
+
# => #<Ladybug::Database:0x0000000121624d10 path:"path/to/mydb" read-only:false>
|
|
39
|
+
|
|
40
|
+
There's also support for passing configuration options to the database
|
|
41
|
+
handle as keyword arguments to the `.database` method:
|
|
42
|
+
|
|
43
|
+
database = Ladybug.database( 'mydb', read_only: true )
|
|
44
|
+
# => #<Ladybug::Database:0x00000001227aa5a8 path:"mydb" read-only:true>
|
|
45
|
+
|
|
46
|
+
Once you have a Ladybug::Database object, you need a connection to actually use it:
|
|
47
|
+
|
|
48
|
+
conn = db.connect
|
|
49
|
+
# => #<Ladybug::Connection:0x0000000122a41f28 threads:16>
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Querying
|
|
53
|
+
|
|
54
|
+
There are two ways of running queries, immediate execution and via a prepared
|
|
55
|
+
statement. Either method returns one or more results as Ladybug::Result objects.
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Results
|
|
59
|
+
|
|
60
|
+
The each result of a query in a query string is returned as a Ladybug::Result. If
|
|
61
|
+
there are more than one queries in the query string, the Results will be
|
|
62
|
+
chained together so they can be iterated over.
|
|
63
|
+
|
|
64
|
+
Each tuple in a Result can be fetched using Ladybug::Result#next, which returns a
|
|
65
|
+
Hash of the variables in the `RETURN` clause, keyed by the column name as a
|
|
66
|
+
`String`:
|
|
67
|
+
|
|
68
|
+
res = conn.query( 'MATCH (a:User)-[f:Follows]->(b:User) RETURN a.name, b.name, f.since;' )
|
|
69
|
+
# => #<Ladybug::Result:0x00000001268449d8 success: true (4 tuples of 3 columns)>
|
|
70
|
+
res.next
|
|
71
|
+
# => {"a.name" => "Adam", "b.name" => "Karissa", "f.since" => 2020}
|
|
72
|
+
res.next
|
|
73
|
+
# => {"a.name" => "Adam", "b.name" => "Zhang", "f.since" => 2020}
|
|
74
|
+
|
|
75
|
+
The value's type will be determined by the Ladybug datatype of that column of the
|
|
76
|
+
result. See Ladybug::Result for a mapping of the types.
|
|
77
|
+
|
|
78
|
+
If there are more tuples to fetch, Ladybug::Result#has_next? will return `true`:
|
|
79
|
+
|
|
80
|
+
res.has_next?
|
|
81
|
+
# => true
|
|
82
|
+
res.next
|
|
83
|
+
# => {"a.name" => "Karissa", "b.name" => "Zhang", "f.since" => 2021}
|
|
84
|
+
res.next
|
|
85
|
+
# => {"a.name" => "Zhang", "b.name" => "Noura", "f.since" => 2022}
|
|
86
|
+
res.has_next?
|
|
87
|
+
# => false
|
|
88
|
+
res.next
|
|
89
|
+
# => nil
|
|
90
|
+
|
|
91
|
+
Ladybug::Result is also Enumerable, so you can `#each` over its tuples:
|
|
92
|
+
|
|
93
|
+
res.each
|
|
94
|
+
# => #<Enumerator: ...>
|
|
95
|
+
res.map do |tuple|
|
|
96
|
+
"%s has followed %s since %s" % tuple.values_at('a.name', 'b.name', 'f.since')
|
|
97
|
+
end
|
|
98
|
+
# => ["Adam has followed Karissa since 2020",
|
|
99
|
+
# "Adam has followed Zhang since 2020",
|
|
100
|
+
# "Karissa has followed Zhang since 2021",
|
|
101
|
+
# "Zhang has followed Noura since 2022"]
|
|
102
|
+
|
|
103
|
+
If the query string has more than one query in it, a separate Ladybug::Result is
|
|
104
|
+
linked to the previous one, and can be fetched using Ladybug::Result#next_set.
|
|
105
|
+
|
|
106
|
+
For example:
|
|
107
|
+
|
|
108
|
+
res = conn.query( <<~END_OF_QUERY )
|
|
109
|
+
MATCH (a:User)-[f:Follows]->(b:User)
|
|
110
|
+
RETURN a.name, b.name, f.since;
|
|
111
|
+
MATCH (u:User) RETURN *
|
|
112
|
+
END_OF_QUERY
|
|
113
|
+
# => #<Ladybug::Result:0x000000011e6faaf8 success: true (4 tuples of 3 columns)>
|
|
114
|
+
res.to_a
|
|
115
|
+
# => [{"a.name" => "Adam", "b.name" => "Karissa", "f.since" => 2020},
|
|
116
|
+
# {"a.name" => "Adam", "b.name" => "Zhang", "f.since" => 2020},
|
|
117
|
+
# {"a.name" => "Karissa", "b.name" => "Zhang", "f.since" => 2021},
|
|
118
|
+
# {"a.name" => "Zhang", "b.name" => "Noura", "f.since" => 2022}]
|
|
119
|
+
res.has_next_set?
|
|
120
|
+
# => true
|
|
121
|
+
res2 = res.next_set
|
|
122
|
+
# => #<Ladybug::Result:0x000000011e338fa0 success: true (4 tuples of 1 columns)>
|
|
123
|
+
res2.to_a
|
|
124
|
+
# => [{"u" => #<Ladybug::Node:0x000000011e7553b8 @id=[0, 0], @label="User",
|
|
125
|
+
# @properties={name: "Adam", age: 30}>},
|
|
126
|
+
# {"u" => #<Ladybug::Node:0x000000011e7551b0 @id=[0, 1], @label="User",
|
|
127
|
+
# @properties={name: "Karissa", age: 40}>},
|
|
128
|
+
# {"u" => #<Ladybug::Node:0x000000011e755048 @id=[0, 2], @label="User",
|
|
129
|
+
# @properties={name: "Zhang", age: 50}>},
|
|
130
|
+
# {"u" => #<Ladybug::Node:0x000000011e754ee0 @id=[0, 3], @label="User",
|
|
131
|
+
# @properties={name: "Noura", age: 25}>}]
|
|
132
|
+
res2.has_next_set?
|
|
133
|
+
# => false
|
|
134
|
+
res2.next_set
|
|
135
|
+
# => nil
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
### Prepared Statements
|
|
139
|
+
|
|
140
|
+
An alternative to using strings to query the database is to used *prepared statements*. These have a number of advantages, such as reusability and using parameters for queries instead of string interpolation.
|
|
141
|
+
|
|
142
|
+
You can create a Ladybug::PreparedStatement by calling Ladybug::Connection#prepare, then execute it one or more times with parameters using Ladybug::PreparedStatement#execute:
|
|
143
|
+
|
|
144
|
+
stmt = conn.prepare( <<~END_OF_QUERY )
|
|
145
|
+
MATCH (a:User)-[f:Follows]->(b:User)
|
|
146
|
+
WHERE a.name = $name
|
|
147
|
+
RETURN a.name, b.name, f.since'
|
|
148
|
+
END_OF_QUERY
|
|
149
|
+
# => #<Ladybug::PreparedStatement:0x000000011e919b68>
|
|
150
|
+
res = stmt.execute( name: "Karissa" )
|
|
151
|
+
# => #<Ladybug::Result:0x000000011ee8df90 success: true (1 tuples of 3 columns)>
|
|
152
|
+
res.to_a
|
|
153
|
+
# => [{"a.name" => "Karissa", "b.name" => "Zhang", "f.since" => 2021}]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
### Result Memory Management
|
|
157
|
+
|
|
158
|
+
Because of the way Ruby frees memory when it's shutting down (i.e., the order is indeterminate), Ladybug::Result objects may not be freed immediately when they go out of scope. To provide some way to manage this, the Ladybug::Result#finish call is provided as a way to explicitly destroy the underlying Ladybug data structure so the Result can be freed. Since this is somewhat inconvenient to manage, there are two forms of Ladybug::Connection#query and Ladybug::PreparedStatement#execute, one which returns a Result and a "bang" equivalent one which just returns success or failure. Additionally, passing a block to either method will yield the Result to the block and then immediately `finish` the Result for you and return the block's value.
|
|
159
|
+
|
|
160
|
+
query_string = 'MATCH (a:User)-[f:Follows]->(b:User) RETURN a.name, b.name, f.since'
|
|
161
|
+
conn.query!( query_string )
|
|
162
|
+
# => true
|
|
163
|
+
conn.query( query_string ) {|res| res.tuples }
|
|
164
|
+
# => [{"a.name" => "Adam", "b.name" => "Karissa", "f.since" => 2020},
|
|
165
|
+
# {"a.name" => "Adam", "b.name" => "Zhang", "f.since" => 2020},
|
|
166
|
+
# {"a.name" => "Karissa", "b.name" => "Zhang", "f.since" => 2021},
|
|
167
|
+
# {"a.name" => "Zhang", "b.name" => "Noura", "f.since" => 2022}]
|
|
168
|
+
|
|
169
|
+
stmt = conn.prepare( "CREATE (:User {name: $name, age: $age})" )
|
|
170
|
+
# => #<Ladybug::PreparedStatement:0x000000010bc7cfe8>
|
|
171
|
+
stmt.execute!( name: 'David', age: 19 )
|
|
172
|
+
# => true
|
|
173
|
+
stmt.execute!( name: 'Agnes', age: 28 )
|
|
174
|
+
# => true
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
## Examples
|
|
178
|
+
|
|
179
|
+
require 'Ladybug'
|
|
180
|
+
|
|
181
|
+
db = Ladybug.database
|
|
182
|
+
conn = db.connect
|
|
183
|
+
conn.run("CREATE NODE TABLE User(name STRING, age INT64, PRIMARY KEY (name))")
|
|
184
|
+
conn.run("CREATE NODE TABLE City(name STRING, population INT64, PRIMARY KEY (name))")
|
|
185
|
+
conn.run("CREATE REL TABLE Follows(FROM User TO User, since INT64)")
|
|
186
|
+
conn.run("CREATE REL TABLE LivesIn(FROM User TO City)")
|
|
187
|
+
|
|
188
|
+
# Load data.
|
|
189
|
+
conn.run("COPY User FROM \"user.csv\"")
|
|
190
|
+
conn.run("COPY City FROM \"city.csv\"")
|
|
191
|
+
conn.run("COPY Follows FROM \"follows.csv\"")
|
|
192
|
+
conn.run("COPY LivesIn FROM \"lives-in.csv\"")
|
|
193
|
+
|
|
194
|
+
# Execute a simple query.
|
|
195
|
+
result = conn.query("MATCH (a:User)-[f:Follows]->(b:User) RETURN a.name, f.since, b.name;")
|
|
196
|
+
|
|
197
|
+
# Output query result.
|
|
198
|
+
result.each do |tuple|
|
|
199
|
+
name, since, name2 = tuple.values_at( 'a.name', 'f.since', 'b.name' )
|
|
200
|
+
puts "%s follows %s since %lld", [ name, name2, since ]
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
result.finish
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
## To-Do List
|
|
207
|
+
|
|
208
|
+
- `UNION` result type.
|
|
209
|
+
- `JSON` result type from the JSON extension
|
|
210
|
+
- Better memory management for Ladybug::Results
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
## Requirements
|
|
214
|
+
|
|
215
|
+
- Ruby >= 3
|
|
216
|
+
- LadybugDB >= 0.12
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
## Install
|
|
220
|
+
|
|
221
|
+
$ gem install ruby-ladybug
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
## Authors
|
|
225
|
+
|
|
226
|
+
- Michael Granger <ged@FaerieMUD.org>
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
## Copyright
|
|
230
|
+
|
|
231
|
+
Copyright (c) 2025-2026 Michael Granger
|
|
232
|
+
|
|
233
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
234
|
+
a copy of this software and associated documentation files (the
|
|
235
|
+
"Software"), to deal in the Software without restriction, including
|
|
236
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
237
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
238
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
239
|
+
the following conditions:
|
|
240
|
+
|
|
241
|
+
The above copyright notice and this permission notice shall be
|
|
242
|
+
included in all copies or substantial portions of the Software.
|
|
243
|
+
|
|
244
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
245
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
246
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
247
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
248
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
249
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
250
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* config.c - Ladybug::Config class
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "ladybug_ext.h"
|
|
7
|
+
|
|
8
|
+
#define CHECK_CONFIG(self) ((lbug_system_config*)rb_check_typeddata((self), &rlbug_config_type))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
VALUE rlbug_cLadybugConfig;
|
|
12
|
+
|
|
13
|
+
static const rb_data_type_t rlbug_config_type = {
|
|
14
|
+
.wrap_struct_name = "Ladybug::Config",
|
|
15
|
+
.function = {},
|
|
16
|
+
.data = NULL,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* ::allocate function
|
|
23
|
+
*/
|
|
24
|
+
static VALUE
|
|
25
|
+
rlbug_config_s_allocate( VALUE klass )
|
|
26
|
+
{
|
|
27
|
+
return TypedData_Wrap_Struct( klass, &rlbug_config_type, NULL );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
lbug_system_config *
|
|
32
|
+
rlbug_get_config( VALUE obj )
|
|
33
|
+
{
|
|
34
|
+
return CHECK_CONFIG( obj );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* call-seq:
|
|
41
|
+
* new() -> config
|
|
42
|
+
*
|
|
43
|
+
* Create a Ladybug::Config with default values.
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
static VALUE
|
|
47
|
+
rlbug_config_initialize( VALUE self )
|
|
48
|
+
{
|
|
49
|
+
lbug_system_config *ptr = CHECK_CONFIG( self );
|
|
50
|
+
|
|
51
|
+
if ( !ptr ) {
|
|
52
|
+
ptr = ALLOC( lbug_system_config );
|
|
53
|
+
lbug_system_config defaults = lbug_default_system_config();
|
|
54
|
+
|
|
55
|
+
ptr->buffer_pool_size = defaults.buffer_pool_size;
|
|
56
|
+
ptr->max_num_threads = defaults.max_num_threads;
|
|
57
|
+
ptr->enable_compression = defaults.enable_compression;
|
|
58
|
+
ptr->read_only = defaults.read_only;
|
|
59
|
+
ptr->max_db_size = defaults.max_db_size;
|
|
60
|
+
ptr->auto_checkpoint = defaults.auto_checkpoint;
|
|
61
|
+
ptr->checkpoint_threshold = defaults.checkpoint_threshold;
|
|
62
|
+
|
|
63
|
+
RTYPEDDATA_DATA( self ) = ptr;
|
|
64
|
+
} else {
|
|
65
|
+
rb_raise( rb_eRuntimeError, "cannot reinit config" );
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
rb_call_super( 0, 0 );
|
|
69
|
+
|
|
70
|
+
return Qtrue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
* call-seq:
|
|
76
|
+
* config.buffer_pool_size() -> integer
|
|
77
|
+
*
|
|
78
|
+
* Return the buffer_pool_size config value.
|
|
79
|
+
*/
|
|
80
|
+
static VALUE
|
|
81
|
+
rlbug_config_buffer_pool_size( VALUE self )
|
|
82
|
+
{
|
|
83
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
84
|
+
return ULONG2NUM( config->buffer_pool_size );
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* call-seq:
|
|
90
|
+
* config.max_num_threads() -> integer
|
|
91
|
+
*
|
|
92
|
+
* Return the max_num_threads config value.
|
|
93
|
+
*/
|
|
94
|
+
static VALUE
|
|
95
|
+
rlbug_config_max_num_threads( VALUE self )
|
|
96
|
+
{
|
|
97
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
98
|
+
return ULONG2NUM( config->max_num_threads );
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
* call-seq:
|
|
104
|
+
* config.enable_compression() -> true or false
|
|
105
|
+
*
|
|
106
|
+
* Return the enable_compression config value.
|
|
107
|
+
*/
|
|
108
|
+
static VALUE
|
|
109
|
+
rlbug_config_enable_compression( VALUE self )
|
|
110
|
+
{
|
|
111
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
112
|
+
return config->enable_compression ? Qtrue : Qfalse;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
* call-seq:
|
|
118
|
+
* config.read_only() -> true or false
|
|
119
|
+
*
|
|
120
|
+
* Return the read_only config value.
|
|
121
|
+
*/
|
|
122
|
+
static VALUE
|
|
123
|
+
rlbug_config_read_only( VALUE self )
|
|
124
|
+
{
|
|
125
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
126
|
+
return config->read_only ? Qtrue : Qfalse;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/*
|
|
131
|
+
* call-seq:
|
|
132
|
+
* config.max_db_size() -> integer
|
|
133
|
+
*
|
|
134
|
+
* Return the max_db_size config value.
|
|
135
|
+
*/
|
|
136
|
+
static VALUE
|
|
137
|
+
rlbug_config_max_db_size( VALUE self )
|
|
138
|
+
{
|
|
139
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
140
|
+
return ULONG2NUM( config->max_db_size );
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
/*
|
|
145
|
+
* call-seq:
|
|
146
|
+
* config.auto_checkpoint() -> true or false
|
|
147
|
+
*
|
|
148
|
+
* Return the auto_checkpoint config value.
|
|
149
|
+
*/
|
|
150
|
+
static VALUE
|
|
151
|
+
rlbug_config_auto_checkpoint( VALUE self )
|
|
152
|
+
{
|
|
153
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
154
|
+
return config->auto_checkpoint ? Qtrue : Qfalse;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/*
|
|
159
|
+
* call-seq:
|
|
160
|
+
* config.checkpoint_threshold() -> integer
|
|
161
|
+
*
|
|
162
|
+
* Return the checkpoint_threshold config value.
|
|
163
|
+
*/
|
|
164
|
+
static VALUE
|
|
165
|
+
rlbug_config_checkpoint_threshold( VALUE self )
|
|
166
|
+
{
|
|
167
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
168
|
+
return ULONG2NUM( config->checkpoint_threshold );
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
/*
|
|
173
|
+
* call-seq:
|
|
174
|
+
* config.buffer_pool_size = integer
|
|
175
|
+
*
|
|
176
|
+
* Set the buffer_pool_size config value.
|
|
177
|
+
*/
|
|
178
|
+
static VALUE
|
|
179
|
+
rlbug_config_buffer_pool_size_eq( VALUE self, VALUE value )
|
|
180
|
+
{
|
|
181
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
182
|
+
config->buffer_pool_size = NUM2ULONG( value );
|
|
183
|
+
|
|
184
|
+
return Qtrue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
/*
|
|
189
|
+
* call-seq:
|
|
190
|
+
* config.max_num_threads = integer
|
|
191
|
+
*
|
|
192
|
+
* Set the max_num_threads config value.
|
|
193
|
+
*/
|
|
194
|
+
static VALUE
|
|
195
|
+
rlbug_config_max_num_threads_eq( VALUE self, VALUE value )
|
|
196
|
+
{
|
|
197
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
198
|
+
config->max_num_threads = NUM2ULONG( value );
|
|
199
|
+
|
|
200
|
+
return Qtrue;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
/*
|
|
205
|
+
* call-seq:
|
|
206
|
+
* config.enable_compression = true or false
|
|
207
|
+
*
|
|
208
|
+
* Set the enable_compression config value.
|
|
209
|
+
*/
|
|
210
|
+
static VALUE
|
|
211
|
+
rlbug_config_enable_compression_eq( VALUE self, VALUE value )
|
|
212
|
+
{
|
|
213
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
214
|
+
config->enable_compression = RTEST( value );
|
|
215
|
+
|
|
216
|
+
return Qtrue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
/*
|
|
221
|
+
* call-seq:
|
|
222
|
+
* config.read_only = true or false
|
|
223
|
+
*
|
|
224
|
+
* Set the read_only config value.
|
|
225
|
+
*/
|
|
226
|
+
static VALUE
|
|
227
|
+
rlbug_config_read_only_eq( VALUE self, VALUE value )
|
|
228
|
+
{
|
|
229
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
230
|
+
config->read_only = RTEST( value );
|
|
231
|
+
|
|
232
|
+
return Qtrue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
/*
|
|
237
|
+
* call-seq:
|
|
238
|
+
* config.max_db_size = integer
|
|
239
|
+
*
|
|
240
|
+
* Set the max_db_size config value.
|
|
241
|
+
*/
|
|
242
|
+
static VALUE
|
|
243
|
+
rlbug_config_max_db_size_eq( VALUE self, VALUE value )
|
|
244
|
+
{
|
|
245
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
246
|
+
config->max_db_size = NUM2ULONG( value );
|
|
247
|
+
|
|
248
|
+
return Qtrue;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
* call-seq:
|
|
254
|
+
* config.auto_checkpoint = true or false
|
|
255
|
+
*
|
|
256
|
+
* Set the auto_checkpoint config value.
|
|
257
|
+
*/
|
|
258
|
+
static VALUE
|
|
259
|
+
rlbug_config_auto_checkpoint_eq( VALUE self, VALUE value )
|
|
260
|
+
{
|
|
261
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
262
|
+
config->auto_checkpoint = RTEST( value );
|
|
263
|
+
|
|
264
|
+
return Qtrue;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
/*
|
|
269
|
+
* call-seq:
|
|
270
|
+
* config.checkpoint_threshold = integer
|
|
271
|
+
*
|
|
272
|
+
* Set the checkpoint_threshold config value.
|
|
273
|
+
*/
|
|
274
|
+
static VALUE
|
|
275
|
+
rlbug_config_checkpoint_threshold_eq( VALUE self, VALUE value )
|
|
276
|
+
{
|
|
277
|
+
lbug_system_config *config = CHECK_CONFIG( self );
|
|
278
|
+
config->checkpoint_threshold = NUM2ULONG( value );
|
|
279
|
+
|
|
280
|
+
return Qtrue;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
/*
|
|
286
|
+
* Document-class: Ladybug::Config
|
|
287
|
+
*/
|
|
288
|
+
void
|
|
289
|
+
rlbug_init_config( void )
|
|
290
|
+
{
|
|
291
|
+
#ifdef FOR_RDOC
|
|
292
|
+
rlbug_mLadybug = rb_define_module( "ladybug" );
|
|
293
|
+
#endif
|
|
294
|
+
|
|
295
|
+
rlbug_cLadybugConfig = rb_define_class_under( rlbug_mLadybug, "Config", rb_cObject );
|
|
296
|
+
|
|
297
|
+
rb_define_alloc_func( rlbug_cLadybugConfig, rlbug_config_s_allocate );
|
|
298
|
+
|
|
299
|
+
rb_define_method( rlbug_cLadybugConfig, "initialize", rlbug_config_initialize, 0 );
|
|
300
|
+
|
|
301
|
+
rb_define_method( rlbug_cLadybugConfig, "buffer_pool_size", rlbug_config_buffer_pool_size, 0 );
|
|
302
|
+
rb_define_method( rlbug_cLadybugConfig, "max_num_threads", rlbug_config_max_num_threads, 0 );
|
|
303
|
+
rb_define_method( rlbug_cLadybugConfig, "enable_compression", rlbug_config_enable_compression, 0 );
|
|
304
|
+
rb_define_method( rlbug_cLadybugConfig, "read_only", rlbug_config_read_only, 0 );
|
|
305
|
+
rb_define_method( rlbug_cLadybugConfig, "max_db_size", rlbug_config_max_db_size, 0 );
|
|
306
|
+
rb_define_method( rlbug_cLadybugConfig, "auto_checkpoint", rlbug_config_auto_checkpoint, 0 );
|
|
307
|
+
rb_define_method( rlbug_cLadybugConfig, "checkpoint_threshold", rlbug_config_checkpoint_threshold, 0 );
|
|
308
|
+
|
|
309
|
+
rb_define_method( rlbug_cLadybugConfig, "buffer_pool_size=", rlbug_config_buffer_pool_size_eq, 1 );
|
|
310
|
+
rb_define_method( rlbug_cLadybugConfig, "max_num_threads=", rlbug_config_max_num_threads_eq, 1 );
|
|
311
|
+
rb_define_method( rlbug_cLadybugConfig, "enable_compression=", rlbug_config_enable_compression_eq, 1 );
|
|
312
|
+
rb_define_method( rlbug_cLadybugConfig, "read_only=", rlbug_config_read_only_eq, 1 );
|
|
313
|
+
rb_define_method( rlbug_cLadybugConfig, "max_db_size=", rlbug_config_max_db_size_eq, 1 );
|
|
314
|
+
rb_define_method( rlbug_cLadybugConfig, "auto_checkpoint=", rlbug_config_auto_checkpoint_eq, 1 );
|
|
315
|
+
rb_define_method( rlbug_cLadybugConfig, "checkpoint_threshold=", rlbug_config_checkpoint_threshold_eq, 1 );
|
|
316
|
+
|
|
317
|
+
rb_require( "ladybug/config" );
|
|
318
|
+
}
|