flexirecord 0.0.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +11 -0
- data/lib/flexirecord.rb +34 -13
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -41,3 +41,14 @@
|
|
41
41
|
- >
|
42
42
|
SELECT DISTINCT has been replaced by SELECT (ALL).
|
43
43
|
|
44
|
+
- Release of version 0.0.6.
|
45
|
+
|
46
|
+
- 2007-02-16:
|
47
|
+
- >
|
48
|
+
Added two documentation comments.
|
49
|
+
|
50
|
+
- 2007-03-01:
|
51
|
+
- >
|
52
|
+
PostgreSQL's types 'date', 'timestamp' and 'timestamptz' now get converted to a ruby Time object, when being read from the database. Ruby Time objects get converted to the following string representation, when being written to the database: 'YYYY-MM-DD HH:MM:SS.uuuuuu+/-hh', where hh is the offset in hours from UTC. This string can be (implicitly or explicitly) type casted by PostgreSQL to a Date/Time type.
|
53
|
+
|
54
|
+
- Release of version 1.0.0.
|
data/lib/flexirecord.rb
CHANGED
@@ -18,13 +18,13 @@ require 'rational'
|
|
18
18
|
#
|
19
19
|
# -----
|
20
20
|
#
|
21
|
-
# FlexiRecord is a library
|
21
|
+
# FlexiRecord is a ruby library providing object oriented access to databases (object-relational mapping). Each table is represented by a class, each row of that table is represented by an object of that class. This library is especially aimed to properly support database transactions. By now only PostgreSQL (version 8.2 or higher!) is supported as a backend.
|
22
22
|
#
|
23
|
-
# Please
|
23
|
+
# Please mind that this is a beta release.
|
24
24
|
#
|
25
25
|
# To use FlexiRecord, you have to first create a new ConnectionPool with ConnectionPool.new. If all tables are stored on the same database, you can directly assign the ConnectionPool to the BaseRecord class, by calling:
|
26
26
|
#
|
27
|
-
# BaseRecord.connection_pool = ConnectionPool.new(...)
|
27
|
+
# FlexiRecord::BaseRecord.connection_pool = FlexiRecord::ConnectionPool.new(...)
|
28
28
|
#
|
29
29
|
# You should also create sub-classes of BaseRecord, representing the tables of your database.
|
30
30
|
#
|
@@ -1120,7 +1120,7 @@ module FlexiRecord
|
|
1120
1120
|
end
|
1121
1121
|
end
|
1122
1122
|
|
1123
|
-
#
|
1123
|
+
# Destroys the record in the database, by executing a DELETE command.
|
1124
1124
|
def destroy
|
1125
1125
|
if self.saved?
|
1126
1126
|
self.class.db_execute('DELETE FROM ' << self.class.table <<
|
@@ -1271,6 +1271,12 @@ module FlexiRecord
|
|
1271
1271
|
command_argument = command_arguments.shift
|
1272
1272
|
if command_argument.kind_of? Rational
|
1273
1273
|
command_argument = command_argument.to_f
|
1274
|
+
elsif command_argument.kind_of? Time
|
1275
|
+
time_offset_hours = command_argument.utc_offset / 3600
|
1276
|
+
unless 3600 * time_offset_hours == command_argument.utc_offset
|
1277
|
+
raise "Time zone offset is not an integer amount of hours."
|
1278
|
+
end
|
1279
|
+
command_argument = "%s.%06i%+03i" % [command_argument.strftime("%Y-%m-%d %H:%M:%S"), command_argument.usec, time_offset_hours]
|
1274
1280
|
end
|
1275
1281
|
PGconn.quote(command_argument) << $1
|
1276
1282
|
# argument = command_arguments.shift
|
@@ -1297,14 +1303,14 @@ module FlexiRecord
|
|
1297
1303
|
nil
|
1298
1304
|
else
|
1299
1305
|
if @data_types
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1306
|
+
data_type = @data_types[backend_result.type(col)]
|
1307
|
+
if data_type == "bool"
|
1308
|
+
value_string[0, 1] == 't'
|
1309
|
+
elsif ["int2", "int4", "int8"].include? data_type
|
1310
|
+
value_string.to_i
|
1311
|
+
elsif ["text", "varchar"].include? data_type
|
1312
|
+
value_string
|
1313
|
+
elsif data_type == "numeric"
|
1308
1314
|
unless value_string =~ /^([0-9]*)(\.([0-9]+)?)?$/
|
1309
1315
|
raise "Unexpected format for numeric data from database."
|
1310
1316
|
end
|
@@ -1313,6 +1319,21 @@ module FlexiRecord
|
|
1313
1319
|
else
|
1314
1320
|
$1.to_i
|
1315
1321
|
end
|
1322
|
+
elsif data_type == "date"
|
1323
|
+
unless value_string =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/
|
1324
|
+
raise "Unexpected format for date from database."
|
1325
|
+
end
|
1326
|
+
Time.local($1.to_i, $2.to_i, $3.to_i)
|
1327
|
+
elsif data_type == "timestamp"
|
1328
|
+
unless value_string =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})(\.([0-9]*))?$/
|
1329
|
+
raise "Unexpected format for timestamp without time zone from database."
|
1330
|
+
end
|
1331
|
+
Time.local($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, $8.to_i)
|
1332
|
+
elsif data_type == "timestamptz"
|
1333
|
+
unless value_string =~ /^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})(\.([0-9]*))?([+-][0-9]{2})$/
|
1334
|
+
aise "Unexpected format for timestamp with time zone from database."
|
1335
|
+
end
|
1336
|
+
(Time.utc($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, $8.to_i) - (3600 * $9.to_i)).localtime
|
1316
1337
|
else
|
1317
1338
|
value_string
|
1318
1339
|
end
|
@@ -1434,7 +1455,7 @@ module FlexiRecord
|
|
1434
1455
|
end
|
1435
1456
|
end
|
1436
1457
|
|
1437
|
-
#
|
1458
|
+
# Closes the connection. The connection object must not be used after it is closed.
|
1438
1459
|
def close
|
1439
1460
|
@backend_connection.close
|
1440
1461
|
@backend_connection = nil
|
metadata
CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: flexirecord
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2007-02
|
8
|
-
summary: Object-Oriented Database Access Library
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2007-03-02 00:00:00 +00:00
|
8
|
+
summary: Object-Oriented Database Access Library (ORM layer)
|
9
9
|
require_paths:
|
10
10
|
- lib/
|
11
11
|
email: jan.behrens@flexiguided.de
|