sql_tools 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sql_tools/column_definition.rb +9 -0
- data/lib/sql_tools/constraint.rb +14 -0
- data/lib/sql_tools/index.rb +28 -0
- data/lib/sql_tools/schema.rb +13 -0
- data/lib/sql_tools/schema_visitor.rb +22 -0
- data/lib/sql_tools/version.rb +1 -1
- data/lib/sql_tools.rb +2 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3b0a5d22da6c9be49114af27655dcffcfb1c0d6e2a045507f81947068dc4b84
|
4
|
+
data.tar.gz: 52003a39612fbb1cb6f778514235957e1024aa95ffd30f50b0f9bee48bba6ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94688c70de849c18bc490b236ad9242518cd659140a5978d6a20d05d619f0b3932d88299e831531a6b8f45d65ee91c1ef3cc6689bf1725bfc1f693f1240aed32
|
7
|
+
data.tar.gz: d825b27eea4c4ee7e96f64c6e4fa4a5cdc6e0fa65f7f46f4d17cbef7aa99c1c1f6b4d58db3df890b12a6a31d7f0ccbc8be3d386a6f94157d59883778cb6dc039
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SqlTools
|
2
|
+
class Index
|
3
|
+
def initialize(node)
|
4
|
+
@node = node
|
5
|
+
end
|
6
|
+
|
7
|
+
def columns
|
8
|
+
@node.query(<<~QUERY).map do |match|
|
9
|
+
(ordered_columns (column name: (identifier) @column_name))
|
10
|
+
QUERY
|
11
|
+
match["column_name"].text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def primary_key?
|
16
|
+
@node.any? { |child| child.type == :keyword_primary } &&
|
17
|
+
@node.any? { |child| child.type == :keyword_key }
|
18
|
+
end
|
19
|
+
|
20
|
+
def name
|
21
|
+
return :primary_key if primary_key?
|
22
|
+
|
23
|
+
@node.name.text.delete("`")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SqlTools
|
2
|
+
class SchemaVisitor < TreeStand::Visitor
|
3
|
+
attr_reader :schema
|
4
|
+
|
5
|
+
def initialize(node)
|
6
|
+
super(node)
|
7
|
+
@schema = Schema.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def on_create_table(node)
|
11
|
+
@schema.create_table = node
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_column_definition(node)
|
15
|
+
@schema.columns << ColumnDefinition.new(node)
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_constraint(node)
|
19
|
+
@schema.constraints << Constraint.from(node)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/sql_tools/version.rb
CHANGED
data/lib/sql_tools.rb
CHANGED
@@ -10,6 +10,8 @@ module SqlTools
|
|
10
10
|
class Error < StandardError; end
|
11
11
|
|
12
12
|
class << self
|
13
|
+
def schema_from_sql(sql) = schema_from_tree(tree_from_sql(sql))
|
14
|
+
def schema_from_tree(tree) = SqlTools::SchemaVisitor.new(tree.root_node).visit.schema
|
13
15
|
def query_from_sql(sql) = query_from_tree(tree_from_sql(sql))
|
14
16
|
def query_from_tree(tree) = SqlTools::QueryVisitor.new(tree.root_node).visit.query
|
15
17
|
def tree_from_sql(sql) = parser.parse_string(sql)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- derekstride
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_tree_sitter
|
@@ -52,7 +52,10 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- exe/install_tree_sitter_sql
|
54
54
|
- lib/sql_tools.rb
|
55
|
+
- lib/sql_tools/column_definition.rb
|
55
56
|
- lib/sql_tools/common_table_expression.rb
|
57
|
+
- lib/sql_tools/constraint.rb
|
58
|
+
- lib/sql_tools/index.rb
|
56
59
|
- lib/sql_tools/inner_join.rb
|
57
60
|
- lib/sql_tools/left_join.rb
|
58
61
|
- lib/sql_tools/predicate.rb
|
@@ -61,6 +64,8 @@ files:
|
|
61
64
|
- lib/sql_tools/query.rb
|
62
65
|
- lib/sql_tools/query_visitor.rb
|
63
66
|
- lib/sql_tools/relation.rb
|
67
|
+
- lib/sql_tools/schema.rb
|
68
|
+
- lib/sql_tools/schema_visitor.rb
|
64
69
|
- lib/sql_tools/selection.rb
|
65
70
|
- lib/sql_tools/version.rb
|
66
71
|
- rakelib/treesitter.rake
|