lowdata 0.4.1 → 0.4.2
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 +4 -4
- data/lib/nesting.rb +1 -1
- data/lib/query_compiler.rb +1 -1
- data/lib/schema.rb +16 -2
- data/lib/version.rb +1 -1
- data/lib/writer.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 27f2f5c6b645472ee8de9fe796bdef23493d50dc234998cb78c4a49d417f6d1b
|
|
4
|
+
data.tar.gz: 2f1fbb112d7dbcc9be8053b660f88a7781196e6a8cfc7e1d23b479651fb0779c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 37de426f6f987b98618492a48c37b060ff732e89b568cbe1ff6032e9805c28d28988deaa25cb236e0a7c2e951fb3d0ccda8dbd4a6b3af740732ec4f714af6b26
|
|
7
|
+
data.tar.gz: a1b741111a08db463198e8d7edd9c84dc6e88ccac97505d00b8608745f176b8d8f527465e30c510e44534792c6e4066e1d694d95edd33bb03e3adbed384ac97f
|
data/lib/nesting.rb
CHANGED
|
@@ -51,7 +51,7 @@ class LowData
|
|
|
51
51
|
raise ConfigError, ConfigError::MISSING_DATABASE if database.nil?
|
|
52
52
|
|
|
53
53
|
@database = database
|
|
54
|
-
@schema = Schema.
|
|
54
|
+
@schema = Schema.for(database)
|
|
55
55
|
@filters = FilterCompiler.new(database:, schema: @schema)
|
|
56
56
|
@orders = OrderCompiler.new(schema: @schema)
|
|
57
57
|
@queries = QueryCompiler.new(database:)
|
data/lib/query_compiler.rb
CHANGED
|
@@ -14,7 +14,7 @@ class LowData
|
|
|
14
14
|
raise ConfigError, ConfigError::MISSING_DATABASE if database.nil?
|
|
15
15
|
|
|
16
16
|
@database = database
|
|
17
|
-
@schema = Schema.
|
|
17
|
+
@schema = Schema.for(database)
|
|
18
18
|
@filters = FilterCompiler.new(database:, schema: @schema)
|
|
19
19
|
@orders = OrderCompiler.new(schema: @schema)
|
|
20
20
|
end
|
data/lib/schema.rb
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class LowData
|
|
4
|
-
# Reads tables, columns and foreign keys from the database, caching each lookup.
|
|
4
|
+
# Reads tables, columns and foreign keys from the database, caching each lookup. Every query shares one per database,
|
|
5
|
+
# so a lookup is made once while the app runs. `Schema.reset` forgets them, as after a migration.
|
|
5
6
|
class Schema
|
|
7
|
+
def self.for(database)
|
|
8
|
+
@instances ||= {}
|
|
9
|
+
@instances[database] ||= new(database:)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.reset
|
|
13
|
+
@instances = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
6
16
|
def initialize(database:)
|
|
7
17
|
@database = database
|
|
8
18
|
@schemas = {}
|
|
@@ -21,10 +31,14 @@ class LowData
|
|
|
21
31
|
@foreign_keys[table] ||= @database.foreign_key_list(table)
|
|
22
32
|
end
|
|
23
33
|
|
|
34
|
+
def tables
|
|
35
|
+
@tables ||= @database.tables
|
|
36
|
+
end
|
|
37
|
+
|
|
24
38
|
# Tables with a foreign key to or from the table.
|
|
25
39
|
def related_tables(table:)
|
|
26
40
|
outgoing = foreign_keys(table:).map { |foreign_key| foreign_key[:table] }
|
|
27
|
-
incoming =
|
|
41
|
+
incoming = tables.select do |other|
|
|
28
42
|
foreign_keys(table: other).any? { |foreign_key| foreign_key[:table] == table }
|
|
29
43
|
end
|
|
30
44
|
|
data/lib/version.rb
CHANGED
data/lib/writer.rb
CHANGED