swift-db-postgres 0.2.7 → 0.3.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.
- data/CHANGELOG +4 -0
- data/README.md +21 -1
- data/ext/swift/db/postgres/adapter.c +6 -2
- data/test/test_adapter.rb +8 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README.md
CHANGED
|
@@ -47,6 +47,26 @@ MRI adapter for PostgreSQL
|
|
|
47
47
|
#insert_id
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
## Connection options
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
╭────────────────────╥────────────┬─────────────╮
|
|
54
|
+
│ Name ║ Default │ Optional │
|
|
55
|
+
╞════════════════════╬════════════╪═════════════╡
|
|
56
|
+
│ db ║ - │ No │
|
|
57
|
+
│ host ║ 127.0.0.1 │ Yes │
|
|
58
|
+
│ port ║ 5432 │ Yes │
|
|
59
|
+
│ user ║ Etc.login │ Yes │
|
|
60
|
+
│ password ║ nil │ Yes │
|
|
61
|
+
│ encoding ║ utf8 │ Yes │
|
|
62
|
+
│ ssl[:sslmode] ║ allow │ Yes │
|
|
63
|
+
│ ssl[:sslcert] ║ nil │ Yes │
|
|
64
|
+
│ ssl[:sslkey] ║ nil │ Yes │
|
|
65
|
+
│ ssl[:sslrootcert] ║ nil │ Yes │
|
|
66
|
+
│ ssl[:sslcrl] ║ nil │ Yes │
|
|
67
|
+
└────────────────────╨────────────┴─────────────┘
|
|
68
|
+
```
|
|
69
|
+
|
|
50
70
|
## Bind parameters and hstore operators
|
|
51
71
|
|
|
52
72
|
Swift::DB::Postgres uses '?' as a bind parameter and replaces them with the '$' equivalents. This causes issues when
|
|
@@ -68,7 +88,7 @@ end
|
|
|
68
88
|
```ruby
|
|
69
89
|
require 'swift/db/postgres'
|
|
70
90
|
|
|
71
|
-
db = Swift::DB::Postgres.new(db: 'swift_test')
|
|
91
|
+
db = Swift::DB::Postgres.new(db: 'swift_test', encoding: 'utf8')
|
|
72
92
|
|
|
73
93
|
db.execute('drop table if exists users')
|
|
74
94
|
db.execute('create table users (id serial, name text, age integer, created_at timestamp)')
|
|
@@ -62,7 +62,7 @@ void append_ssl_option(char *buffer, int size, VALUE ssl, char *key, char *fallb
|
|
|
62
62
|
|
|
63
63
|
VALUE db_postgres_adapter_initialize(VALUE self, VALUE options) {
|
|
64
64
|
char *connection_info;
|
|
65
|
-
VALUE db, user, pass, host, port, ssl;
|
|
65
|
+
VALUE db, user, pass, host, port, ssl, enc;
|
|
66
66
|
Adapter *a = db_postgres_adapter_handle(self);
|
|
67
67
|
|
|
68
68
|
if (TYPE(options) != T_HASH)
|
|
@@ -74,6 +74,7 @@ VALUE db_postgres_adapter_initialize(VALUE self, VALUE options) {
|
|
|
74
74
|
host = rb_hash_aref(options, ID2SYM(rb_intern("host")));
|
|
75
75
|
port = rb_hash_aref(options, ID2SYM(rb_intern("port")));
|
|
76
76
|
ssl = rb_hash_aref(options, ID2SYM(rb_intern("ssl")));
|
|
77
|
+
enc = rb_hash_aref(options, ID2SYM(rb_intern("encoding")));
|
|
77
78
|
|
|
78
79
|
if (NIL_P(db))
|
|
79
80
|
rb_raise(eSwiftConnectionError, "Invalid db name");
|
|
@@ -83,6 +84,8 @@ VALUE db_postgres_adapter_initialize(VALUE self, VALUE options) {
|
|
|
83
84
|
port = rb_str_new2("5432");
|
|
84
85
|
if (NIL_P(user))
|
|
85
86
|
user = sUser;
|
|
87
|
+
if (NIL_P(enc))
|
|
88
|
+
enc = rb_str_new2("utf8");
|
|
86
89
|
|
|
87
90
|
if (!NIL_P(ssl) && TYPE(ssl) != T_HASH)
|
|
88
91
|
rb_raise(eSwiftArgumentError, "ssl options needs to be a hash");
|
|
@@ -108,7 +111,8 @@ VALUE db_postgres_adapter_initialize(VALUE self, VALUE options) {
|
|
|
108
111
|
rb_raise(eSwiftConnectionError, PQerrorMessage(a->connection));
|
|
109
112
|
|
|
110
113
|
PQsetNoticeProcessor(a->connection, (PQnoticeProcessor)db_postgres_adapter_notice, (void*)self);
|
|
111
|
-
PQsetClientEncoding(a->connection,
|
|
114
|
+
if (PQsetClientEncoding(a->connection, CSTRING(enc)) != 0)
|
|
115
|
+
rb_raise(eSwiftConnectionError, PQerrorMessage(a->connection));
|
|
112
116
|
return self;
|
|
113
117
|
}
|
|
114
118
|
|
data/test/test_adapter.rb
CHANGED
|
@@ -5,6 +5,14 @@ describe 'postgres adapter' do
|
|
|
5
5
|
assert db
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
it 'it should allow custom encoding' do
|
|
9
|
+
assert Swift::DB::Postgres.new(db: 'swift_test', encoding: 'utf8')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'should raise connection error on not so awesome encoding' do
|
|
13
|
+
assert_raises(Swift::ConnectionError) {Swift::DB::Postgres.new(db: 'swift_test', encoding: 'not_awesome')}
|
|
14
|
+
end
|
|
15
|
+
|
|
8
16
|
it 'should execute sql' do
|
|
9
17
|
assert db.execute("select * from pg_tables")
|
|
10
18
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: swift-db-postgres
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rake
|