db_schema-reader-postgres 0.1 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 06c75ff7d43c7a7fcf852e6e96a2cea6da4e517c
4
- data.tar.gz: 69866cfefe8454539deca882a00cdbd3f85c1238
2
+ SHA256:
3
+ metadata.gz: 9f12b3dcea5dc1a301418825e2b8da015e078c520195e42517da991830d3bc22
4
+ data.tar.gz: 52778450688b800dccf4934525fc567f0d99a9b426095298f198728cb827a9e6
5
5
  SHA512:
6
- metadata.gz: d51763814f5e752b7b5a313287780aa39e4e5a7ccf32649620251b128673006f16ccc8192f43ee3a54d47e1644897eeff602b2b3b15ffdf6987245cf774fe816
7
- data.tar.gz: 6bfb55ff18fde36a8efaac023a8ef07e211daa040d99477797c9a16878253b4da9eb058709f7789c0662a4b7dd313a64ecf3f64914c65f6a00ea42cef375431b
6
+ metadata.gz: 7c222884746207d2c46ab112ed40b7d78b4de10feef39dbeee650fa0b40c58bd00307c121ce1fa550391379aa61e80a4d78275e7c2782394f4e91153be986997
7
+ data.tar.gz: 7ec7a253c3ca0c576b6935df764a24456994b8a26a045d5614445164399dff84568c424d11955ab4560542eef9ec8d340c215ee82145c7b585b27c38b5cf003a
data/.travis.yml CHANGED
@@ -5,3 +5,9 @@ rvm:
5
5
  - 2.3.5
6
6
  - 2.4.2
7
7
  before_install: gem install bundler -v 1.16.0
8
+ services:
9
+ - postgresql
10
+ addons:
11
+ postgresql: 9.6
12
+ before_script:
13
+ - psql -c 'CREATE DATABASE db_schema_test;' -U postgres
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # DbSchema::Reader::Postgres
1
+ # DbSchema::Reader::Postgres [![Build Status](https://travis-ci.org/db-schema/reader-postgres.svg?branch=master)](https://travis-ci.org/db-schema/reader-postgres)
2
2
 
3
3
  DbSchema::Reader::Postgres is a library for reading the database
4
4
  structure from PostgreSQL.
@@ -26,7 +26,7 @@ $ gem install db_schema-reader-postgres
26
26
 
27
27
  First you need a Sequel connection object with `:pg_enum` and `:pg_array`
28
28
  Sequel extensions enabled; once you have that object just pass it to
29
- the `.read_schema` method to get full database schema definition:
29
+ `DbSchema::Reader::Postgres.new` to construct the reader:
30
30
 
31
31
  ``` ruby
32
32
  connection = Sequel.connect(adapter: 'postgres', database: 'db_schema_test').tap do |db|
@@ -34,24 +34,30 @@ connection = Sequel.connect(adapter: 'postgres', database: 'db_schema_test').tap
34
34
  db.extension :pg_array
35
35
  end
36
36
 
37
- DbSchema::Reader::Postgres.read_schema(connection)
37
+ reader = DbSchema::Reader::Postgres.new(connection)
38
+ ```
39
+
40
+ You can call `#read_schema` to get the full database schema definition:
41
+
42
+ ``` ruby
43
+ reader.read_schema
38
44
  # => #<DbSchema::Definitions::Schema ...>
39
45
  ```
40
46
 
41
- Other useful methods are `.read_tables`, `.read_table`, `.read_enums` & `.read_extensions`;
47
+ Other useful methods are `#read_tables`, `#read_table`, `#read_enums` & `#read_extensions`;
42
48
  they return definitions of respective parts of the database schema:
43
49
 
44
50
  ``` ruby
45
- DbSchema::Reader::Postgres.read_tables(connection)
51
+ reader.read_tables
46
52
  # => [#<DbSchema::Definitions::Table ...>, #<DbSchema::Definitions::Table ...>, ...]
47
53
 
48
- DbSchema::Reader::Postgres.read_table(:users, connection)
54
+ reader.read_table(:users)
49
55
  # => #<DbSchema::Definitions::Table name=:users ...>
50
56
 
51
- DbSchema::Reader::Postgres.read_enums(connection)
57
+ reader.read_enums
52
58
  # => [#<DbSchema::Definitions::Enum ...>, #<DbSchema::Definitions::Enum ...>, ...]
53
59
 
54
- DbSchema::Reader::Postgres.read_extensions(connection)
60
+ reader.read_extensions
55
61
  # => [#<DbSchema::Definitions::Extension ...>, #<DbSchema::Definitions::Extension ...>, ...]
56
62
  ```
57
63
 
@@ -4,7 +4,7 @@ require_relative 'postgres/version'
4
4
 
5
5
  module DbSchema
6
6
  module Reader
7
- module Postgres
7
+ class Postgres
8
8
  ENUMS_QUERY = <<-SQL.freeze
9
9
  SELECT t.typname AS name,
10
10
  array_agg(e.enumlabel ORDER BY e.enumsortorder) AS values
@@ -20,35 +20,39 @@ SELECT extname
20
20
  WHERE extname != 'plpgsql'
21
21
  SQL
22
22
 
23
- class << self
24
- def read_schema(connection)
25
- Definitions::Schema.new(
26
- tables: read_tables(connection),
27
- enums: read_enums(connection),
28
- extensions: read_extensions(connection)
29
- )
30
- end
23
+ attr_reader :connection
31
24
 
32
- def read_tables(connection)
33
- connection.tables.map do |table_name|
34
- read_table(table_name, connection)
35
- end
36
- end
25
+ def initialize(connection)
26
+ @connection = connection
27
+ end
28
+
29
+ def read_schema
30
+ Definitions::Schema.new(
31
+ tables: read_tables,
32
+ enums: read_enums,
33
+ extensions: read_extensions
34
+ )
35
+ end
37
36
 
38
- def read_table(table_name, connection)
39
- Table.new(connection, table_name).read
37
+ def read_tables
38
+ connection.tables.map do |table_name|
39
+ read_table(table_name)
40
40
  end
41
+ end
42
+
43
+ def read_table(table_name)
44
+ Table.new(connection, table_name).read
45
+ end
41
46
 
42
- def read_enums(connection)
43
- connection[ENUMS_QUERY].map do |enum_data|
44
- Definitions::Enum.new(enum_data[:name].to_sym, enum_data[:values].map(&:to_sym))
45
- end
47
+ def read_enums
48
+ connection[ENUMS_QUERY].map do |enum_data|
49
+ Definitions::Enum.new(enum_data[:name].to_sym, enum_data[:values].map(&:to_sym))
46
50
  end
51
+ end
47
52
 
48
- def read_extensions(connection)
49
- connection[EXTENSIONS_QUERY].map do |extension_data|
50
- Definitions::Extension.new(extension_data[:extname].to_sym)
51
- end
53
+ def read_extensions
54
+ connection[EXTENSIONS_QUERY].map do |extension_data|
55
+ Definitions::Extension.new(extension_data[:extname].to_sym)
52
56
  end
53
57
  end
54
58
  end
@@ -1,6 +1,6 @@
1
1
  module DbSchema
2
2
  module Reader
3
- module Postgres
3
+ class Postgres
4
4
  class Table
5
5
  DEFAULT_VALUE = /\A(
6
6
  ('(?<date>\d{4}-\d{2}-\d{2})'::date)
@@ -1,7 +1,7 @@
1
1
  module DbSchema
2
2
  module Reader
3
- module Postgres
4
- VERSION = '0.1'
3
+ class Postgres
4
+ VERSION = '0.1.1'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_schema-reader-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vsevolod Romashov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  version: '0'
208
208
  requirements: []
209
209
  rubyforge_project:
210
- rubygems_version: 2.6.13
210
+ rubygems_version: 2.7.6
211
211
  signing_key:
212
212
  specification_version: 4
213
213
  summary: Database schema reader for PostgreSQL