rdo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ require "rspec"
2
+ require "rdo"
3
+
4
+ Dir[File.expand_path("../support/**/*.rb", __FILE__)].each do |file|
5
+ require file
6
+ end
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_with :rspec
10
+ end
@@ -0,0 +1,38 @@
1
+ require "rdo"
2
+
3
+ module RDO
4
+ class DriverWithEverything < Driver
5
+ class Executor
6
+ def execute(*args)
7
+ Result.new([])
8
+ end
9
+ end
10
+
11
+ def open
12
+ @open = true
13
+ end
14
+
15
+ def open?
16
+ !!@open
17
+ end
18
+
19
+ def close
20
+ !(@open = false)
21
+ end
22
+
23
+ def execute(stmt, *args)
24
+ Result.new([])
25
+ end
26
+
27
+ def prepare(stmt)
28
+ Statement.new(Executor.new)
29
+ end
30
+
31
+ def quote(str)
32
+ "quoted"
33
+ end
34
+ end
35
+
36
+ Connection.register_driver(:rdo_with_all, DriverWithEverything)
37
+ end
38
+
@@ -0,0 +1,23 @@
1
+ require "rdo"
2
+
3
+ module RDO
4
+ class DriverWithoutStatements < Driver
5
+ def open
6
+ @open = true
7
+ end
8
+
9
+ def open?
10
+ !!@open
11
+ end
12
+
13
+ def close
14
+ !(@open = false)
15
+ end
16
+
17
+ def execute(stmt, *args)
18
+ Result.new([])
19
+ end
20
+ end
21
+
22
+ Connection.register_driver(:rdo_without_stmt, DriverWithoutStatements)
23
+ end
data/util/macros.h ADDED
@@ -0,0 +1,177 @@
1
+ /*
2
+ * RDO Postgres Driver.
3
+ * Copyright © 2012 Chris Corbyn.
4
+ *
5
+ * See LICENSE file for details.
6
+ */
7
+
8
+ /** -------------------------------------------------------------------------
9
+ * These macros are for use by RDO driver developers.
10
+ *
11
+ * They simplify the logic needed when converting types provided by the RDBMS
12
+ * into their equivalent Ruby types.
13
+ *
14
+ * All of these macros take a C string and return a Ruby VALUE.
15
+ *
16
+ * The actual logic for many of the conversions is handled in RDO::Util, which
17
+ * is written in Ruby.
18
+ * --------------------------------------------------------------------------
19
+ */
20
+
21
+ /**
22
+ * Convert a C string to a ruby String.
23
+ *
24
+ * @param (char *) s
25
+ * a C string that is valid in the default encoding
26
+ *
27
+ * @param (size_t) len
28
+ * the length of the string
29
+ *
30
+ * @return VALUE (String)
31
+ * a Ruby String
32
+ */
33
+ #define RDO_STRING(s, len, enc) ( \
34
+ rb_enc_associate_index(rb_str_new(s, len), enc > 0 ? enc : 0) \
35
+ )
36
+
37
+ /**
38
+ * Convert a C string to a ruby String, assuming possible NULL bytes.
39
+ *
40
+ * @param (char *) s
41
+ * a C string, possibly containing nulls
42
+ *
43
+ * @param (size_t) len
44
+ * the length of the string
45
+ *
46
+ * @return VALUE (String)
47
+ * a Ruby String
48
+ */
49
+ #define RDO_BINARY_STRING(s, len) (rb_str_new(s, len))
50
+
51
+ /**
52
+ * Convert a C string to a Fixnum.
53
+ */
54
+ #define RDO_FIXNUM(s) (rb_cstr2inum(s, 10))
55
+
56
+ /**
57
+ * Convert a C string to a Float.
58
+ *
59
+ * This supports Infinity and NaN.
60
+ *
61
+ * @param (char *) s
62
+ * a C string representing a float (e.g. "1.234")
63
+ *
64
+ * @return VALUE (Float)
65
+ * a ruby Float
66
+ */
67
+ #define RDO_FLOAT(s) ( \
68
+ rb_funcall(rb_path2class("RDO::Util"), \
69
+ rb_intern("float"), 1, \
70
+ rb_str_new2(s)) \
71
+ )
72
+
73
+ /**
74
+ * Convert a C string representing a precision decimal into a BigDecimal.
75
+ *
76
+ * @param (char *) s
77
+ * a C string representing a decimal ("1.245")
78
+ *
79
+ * @return VALUE (BigDecimal)
80
+ * a BigDecimal representation of this string
81
+ *
82
+ * @example
83
+ * RDO_DECIMAL("1.234")
84
+ * => #<BigDecimal:7feb42b2b6e8,'0.1234E1',18(18)>
85
+ */
86
+ #define RDO_DECIMAL(s) ( \
87
+ rb_funcall(rb_path2class("RDO::Util"), \
88
+ rb_intern("decimal"), 1, \
89
+ rb_str_new2(s)) \
90
+ )
91
+
92
+ /**
93
+ * Convert a C string representing a date into a Date.
94
+ *
95
+ * @param (char *) s
96
+ * the C string with a parseable date
97
+ *
98
+ * @return VALUE (Date)
99
+ * a Date, exactly as was specified in the input
100
+ *
101
+ * @example
102
+ * RDO_DATE("431-09-22 BC")
103
+ * #<Date: -0430-09-22 ((1564265j,0s,0n),+0s,2299161j)>
104
+ */
105
+ #define RDO_DATE(s) ( \
106
+ rb_funcall(rb_path2class("RDO::Util"), \
107
+ rb_intern("date"), 1, \
108
+ rb_str_new2(s)) \
109
+ )
110
+
111
+ /**
112
+ * Convert a C string representing a date & time with no time zone into a DateTime.
113
+ *
114
+ * @param (char *) s
115
+ * the C string with the date & time provided
116
+ *
117
+ * @return VALUE (DateTime)
118
+ * a DateTime, assuming the system time zone
119
+ *
120
+ * @example
121
+ * RDO_DATE_TIME_WITHOUT_ZONE("2012-09-22 04:36:12")
122
+ * #<DateTime: 2012-09-22T04:36:12+10:00 ((2456192j,66972s,0n),+36000s,2299161j)>
123
+ */
124
+ #define RDO_DATE_TIME_WITHOUT_ZONE(s) ( \
125
+ rb_funcall(rb_path2class("RDO::Util"), \
126
+ rb_intern("date_time_without_zone"), 1, \
127
+ rb_str_new2(s)) \
128
+ )
129
+
130
+ /**
131
+ * Convert a C string representing a date & time that includes a time zone into a DateTime.
132
+ *
133
+ * @param (char *) s
134
+ * the C string with the date & time provided, including the time zone
135
+ *
136
+ * @return VALUE (DateTime)
137
+ * a DateTime, exactly as was specified in the input
138
+ *
139
+ * @example
140
+ * RDO_DATE_TIME_WITHOUT_ZONE("2012-09-22 04:36:12+10:00")
141
+ * #<DateTime: 2012-09-22T04:36:12+10:00 ((2456192j,66972s,0n),+36000s,2299161j)>
142
+ */
143
+ #define RDO_DATE_TIME_WITH_ZONE(s) ( \
144
+ rb_funcall(rb_path2class("RDO::Util"), \
145
+ rb_intern("date_time_with_zone"), 1, \
146
+ rb_str_new2(s)) \
147
+ )
148
+
149
+ /**
150
+ * Convert a boolean string to TrueClass/FalseClass.
151
+ *
152
+ * @param (char *) s
153
+ * a C string that is either 't', 'true', 'f' or 'false'
154
+ *
155
+ * @return VALUE (TrueClass, FalseClass)
156
+ * the boolean representation
157
+ */
158
+ #define RDO_BOOL(s) ((s[0] == 't') ? Qtrue : Qfalse)
159
+
160
+ /**
161
+ * Wrap the given StatementExecutor in a RDO::Statement.
162
+ *
163
+ * @param VALUE
164
+ * any object that responds to #command and #execute
165
+ *
166
+ * @return VALUE
167
+ * an RDO::Statement
168
+ */
169
+ #define RDO_STATEMENT(executor) ( \
170
+ rb_funcall(rb_path2class("RDO::Statement"), \
171
+ rb_intern("new"), 1, executor) \
172
+ )
173
+
174
+ /**
175
+ * Convenience to call #to_s on any Ruby object.
176
+ */
177
+ #define RDO_OBJ_TO_S(obj) (rb_funcall(obj, rb_intern("to_s"), 0))
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - d11wtq
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! "== Ruby Data Objects\n\nIf you're building something in Ruby that
31
+ needs access to a database, you may\nopt to use an ORM like ActiveRecord, DataMapper
32
+ or Sequel. But if your needs\ndon't fit well with an ORM (maybe you're even writing
33
+ an ORM?) then you'll\nneed some other way of talking to your database.\n\nRDO provides
34
+ a common interface to a number of RDBMS backends, using a clean\nRuby syntax, while
35
+ supporting all the functionality you'd expect from a robust\ndatabase connection
36
+ library:\n\n - Connect to different types of RDBMS in a consistent way\n - Type
37
+ casting\n - Safe parameterization of queries\n - Buffered query results\n - Fetching
38
+ meta data from executed commands\n - Access RETURNING values just like any read
39
+ query\n - Prepared statements (emulated where no native support exists)\n - Simple
40
+ core ruby data types\n\n=== RDBMS Support\n\nSupport for each RDBMS is provided
41
+ in separate gems, so as to minimize the\ninstallation requirements. Many gems are
42
+ maintained by separate users who\nwork more closely with those RDBMS's.\n\nDue to
43
+ the nature of this gem, most of the nitty-gritty code is actually\nwritten in C.\n\nSee
44
+ the official README for full details."
45
+ email:
46
+ - chris@w3style.co.uk
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - .gitignore
52
+ - .rspec
53
+ - Gemfile
54
+ - LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - lib/rdo.rb
58
+ - lib/rdo/connection.rb
59
+ - lib/rdo/driver.rb
60
+ - lib/rdo/emulated_statement_executor.rb
61
+ - lib/rdo/exception.rb
62
+ - lib/rdo/result.rb
63
+ - lib/rdo/statement.rb
64
+ - lib/rdo/util.rb
65
+ - lib/rdo/version.rb
66
+ - rdo.gemspec
67
+ - spec/rdo/connection_spec.rb
68
+ - spec/rdo/driver_spec.rb
69
+ - spec/rdo/emulated_statements_spec.rb
70
+ - spec/rdo/result_spec.rb
71
+ - spec/rdo/statement_spec.rb
72
+ - spec/rdo/util_spec.rb
73
+ - spec/spec_helper.rb
74
+ - spec/support/driver_with_everything.rb
75
+ - spec/support/driver_without_statements.rb
76
+ - util/macros.h
77
+ homepage: https://github.com/d11wtq/rdo
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.24
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: RDO—Ruby Data Objects—A robust RDBMS connection layer
101
+ test_files:
102
+ - spec/rdo/connection_spec.rb
103
+ - spec/rdo/driver_spec.rb
104
+ - spec/rdo/emulated_statements_spec.rb
105
+ - spec/rdo/result_spec.rb
106
+ - spec/rdo/statement_spec.rb
107
+ - spec/rdo/util_spec.rb
108
+ - spec/spec_helper.rb
109
+ - spec/support/driver_with_everything.rb
110
+ - spec/support/driver_without_statements.rb