ordlite 0.2.1 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/lib/ordlite/importer.rb +73 -17
- data/lib/ordlite/models/inscribe.rb +70 -18
- data/lib/ordlite/schema.rb +3 -20
- data/lib/ordlite/version.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44ca59e7026e8b717d26f8ae42ed7050d08abd44047dca6de505582253e2f22b
|
4
|
+
data.tar.gz: f2728433967a7d58612e68d0402a3d9c9c9b644e71bdfe6c4aeca2e103cd116f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfd8030275128218b5057c0ed7a585f5a1688acfe894da4183e7e788b26b239565f84ac25bead42cf144d393a1e04ee68c900b918d15b8d4202267d2cad4815
|
7
|
+
data.tar.gz: af1eab5bb9c6e88b698ccd485ef6d8fc08bcd0f2c714faed0ee66d30c834d9ecc2c250c2792285f772a705a33cf5d13fa558965207d6d237b161de6e9c2ff3dc
|
data/CHANGELOG.md
CHANGED
data/lib/ordlite/importer.rb
CHANGED
@@ -125,17 +125,70 @@ def import_csv( path, content: true )
|
|
125
125
|
end
|
126
126
|
end # method import_csv
|
127
127
|
|
128
|
+
|
128
129
|
def import( id_or_ids, content: true )
|
130
|
+
## note: support (integer) numbers too (e.g. 0/1/2, etc.)
|
129
131
|
if id_or_ids.is_a?( String )
|
130
132
|
id = id_or_ids
|
131
133
|
_import( id, content: content )
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
134
|
+
elsif id_or_ids.is_a?( Integer )
|
135
|
+
num = id_or_ids
|
136
|
+
_import_by_num( num, content: content )
|
137
|
+
elsif id_or_ids.is_a?( Array )
|
138
|
+
if id_or_ids.empty? ## id_or_ids.size == 0
|
139
|
+
## do nothing; empty array
|
140
|
+
else
|
141
|
+
first = id_or_ids[0]
|
142
|
+
if first.is_a?( String )
|
143
|
+
ids = id_or_ids
|
144
|
+
ids.each do |id|
|
145
|
+
_import( id, content: content )
|
146
|
+
end
|
147
|
+
elsif first.is_a?( Integer )
|
148
|
+
nums = id_or_ids
|
149
|
+
nums.each do |num|
|
150
|
+
_import_by_num( num, content: content )
|
151
|
+
end
|
152
|
+
elsif first.is_a?( Hash ) && first.has_key?( 'id' )
|
153
|
+
## try to get ids with records
|
154
|
+
recs = id_or_ids
|
155
|
+
ids = recs.map {|rec| rec['id'] }
|
156
|
+
ids.each do |id|
|
157
|
+
_import( id, content: content )
|
158
|
+
end
|
159
|
+
elsif first.is_a?( Hash ) && first.has_key?( 'num' )
|
160
|
+
## try to get nums with records
|
161
|
+
recs = id_or_ids
|
162
|
+
nums = recs.map {|rec| rec['num'] }
|
163
|
+
nums.each do |num|
|
164
|
+
## note: support numbers as strings too
|
165
|
+
num = num.to_i(10) if num.is_a?( String )
|
166
|
+
_import_by_num( num, content: content )
|
167
|
+
end
|
168
|
+
else
|
169
|
+
raise ArgumentError, "expected Array of String|Integer or Hash (with keys id|num); got #{first.class.name}"
|
170
|
+
end
|
136
171
|
end
|
172
|
+
else
|
173
|
+
raise ArgumentError, "expected String or Array; got #{id_or_ids.class.name}"
|
137
174
|
end
|
138
|
-
end
|
175
|
+
end # method import
|
176
|
+
|
177
|
+
|
178
|
+
def _import_content( id )
|
179
|
+
## check if (content) blob is already in db?
|
180
|
+
blob = Blob.find_by( id: id )
|
181
|
+
if blob ## already in db; do nothing
|
182
|
+
else ## fetch via ordinals.com api and update db
|
183
|
+
content = Ordinals.content( id )
|
184
|
+
|
185
|
+
puts " content-type: #{content.type}"
|
186
|
+
puts " content-length: #{content.length}"
|
187
|
+
|
188
|
+
Blob.create( id: id, content: content.data )
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
139
192
|
|
140
193
|
def _import( id, content: true )
|
141
194
|
## check if inscription / inscribe is already in db?
|
@@ -149,19 +202,22 @@ def _import( id, content: true )
|
|
149
202
|
Inscribe.create_from_api( data )
|
150
203
|
end
|
151
204
|
|
152
|
-
if content
|
153
|
-
|
154
|
-
blob = Blob.find_by( id: id )
|
155
|
-
if blob ## already in db; do nothing
|
156
|
-
else ## fetch via ordinals.com api and update db
|
157
|
-
content = Ordinals.content( id )
|
205
|
+
_import_content( id ) if content
|
206
|
+
end
|
158
207
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
208
|
+
def _import_by_num( num, content: true )
|
209
|
+
## check if inscription / inscribe is already in db?
|
210
|
+
inscribe = Inscribe.find_by( num: num )
|
211
|
+
if inscribe ## already in db; dump record
|
212
|
+
## pp inscribe
|
213
|
+
else ## fetch via ordinals.com api and update db
|
214
|
+
data = Ordinals.inscription( num )
|
215
|
+
|
216
|
+
pp data
|
217
|
+
inscribe = Inscribe.create_from_api( data )
|
218
|
+
end
|
219
|
+
|
220
|
+
_import_content( inscribe.id ) if content
|
165
221
|
end
|
166
222
|
|
167
223
|
end # class Importer
|
@@ -18,6 +18,68 @@ module OrdDb
|
|
18
18
|
|
19
19
|
################################
|
20
20
|
### scope like helpers
|
21
|
+
def self.png() where( content_type: 'image/png' ); end
|
22
|
+
def self.gif() where( content_type: 'image/gif' ); end
|
23
|
+
def self.jpg() where( content_type: 'image/jpeg' ); end
|
24
|
+
def self.webp() where( content_type: 'image/webp' ); end
|
25
|
+
def self.svg() where( content_type: 'image/svg+xml' ); end
|
26
|
+
def self.avif() where( content_type: 'image/avif' ); end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
alias_method :jpeg, :jpg
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.image
|
33
|
+
## change to/or add alias e.g. image/images - why? why not
|
34
|
+
where( content_type: [
|
35
|
+
'image/png',
|
36
|
+
'image/jpeg',
|
37
|
+
'image/gif',
|
38
|
+
'image/webp',
|
39
|
+
'image/svg+xml',
|
40
|
+
'image/avif',
|
41
|
+
])
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.html
|
45
|
+
where( content_type: [
|
46
|
+
'text/html;charset=utf-8',
|
47
|
+
'text/html',
|
48
|
+
])
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.js
|
52
|
+
where( content_type: [
|
53
|
+
'text/javascript',
|
54
|
+
'application/javascript',
|
55
|
+
])
|
56
|
+
end
|
57
|
+
|
58
|
+
class << self
|
59
|
+
alias_method :javascript, :js
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.text
|
63
|
+
## change to/or add alias e.g. text/texts - why? why not
|
64
|
+
## include html or svg in text-only inscription - why? why not?
|
65
|
+
## include markdown in text-only inscription - why? why not?
|
66
|
+
## make content_type lower case with lower() - why? why not?
|
67
|
+
where( content_type: [
|
68
|
+
'text/plain',
|
69
|
+
'text/plain;charset=utf-8',
|
70
|
+
'text/plain;charset=us-ascii',
|
71
|
+
'application/json',
|
72
|
+
])
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.search( q ) ## "full-text" search helper
|
76
|
+
## rename to text_search - why? why not?
|
77
|
+
## auto-sort by num - why? why not?
|
78
|
+
joins(:blob).text.where( "content LIKE '%#{q}%'" ).order('num')
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
21
83
|
def self.deploys
|
22
84
|
where_clause =<<SQL
|
23
85
|
content LIKE '%deploy%'
|
@@ -25,7 +87,7 @@ AND ( content LIKE '%orc-721%'
|
|
25
87
|
OR content LIKE '%og%')
|
26
88
|
SQL
|
27
89
|
|
28
|
-
joins(:blob).where( where_clause ).order( 'num' )
|
90
|
+
joins(:blob).text.where( where_clause ).order( 'num' )
|
29
91
|
end
|
30
92
|
|
31
93
|
def self.deploys_by( slug: )
|
@@ -36,7 +98,7 @@ AND ( content LIKE '%orc-721%'
|
|
36
98
|
AND content LIKE '%#{slug}%'
|
37
99
|
SQL
|
38
100
|
|
39
|
-
joins(:blob).where( where_clause ).order( 'num' )
|
101
|
+
joins(:blob).text.where( where_clause ).order( 'num' )
|
40
102
|
end
|
41
103
|
|
42
104
|
def self.mints
|
@@ -46,7 +108,7 @@ AND ( content LIKE '%orc-721%'
|
|
46
108
|
OR content LIKE '%og%')
|
47
109
|
SQL
|
48
110
|
|
49
|
-
joins(:blob).where( where_clause ).order( 'num' )
|
111
|
+
joins(:blob).text.where( where_clause ).order( 'num' )
|
50
112
|
end
|
51
113
|
|
52
114
|
def self.mints_by( slug: )
|
@@ -57,9 +119,10 @@ AND ( content LIKE '%orc-721%'
|
|
57
119
|
AND content LIKE '%#{slug}%'
|
58
120
|
SQL
|
59
121
|
|
60
|
-
joins(:blob).where( where_clause ).order( 'num' )
|
122
|
+
joins(:blob).text.where( where_clause ).order( 'num' )
|
61
123
|
end
|
62
124
|
|
125
|
+
|
63
126
|
def self.sub1k() where( 'num < 1000' ); end
|
64
127
|
def self.sub2k() where( 'num < 2000' ); end
|
65
128
|
def self.sub10k() where( 'num < 10000' ); end
|
@@ -129,23 +192,12 @@ SQL
|
|
129
192
|
end
|
130
193
|
|
131
194
|
|
132
|
-
|
133
|
-
## note: for now include:
|
134
|
-
## - text/plain (all variants)
|
135
|
-
## - text/json (all variants)
|
136
|
-
## - text/markdown
|
137
|
-
where( content_type:
|
138
|
-
['text/plain',
|
139
|
-
'text/plain;charset=utf-8',
|
140
|
-
'text/markdown',
|
141
|
-
'application/json',
|
142
|
-
]
|
143
|
-
)
|
144
|
-
end
|
145
|
-
def self.png() where( content_type: 'image/png' ); end
|
195
|
+
|
146
196
|
|
147
197
|
###
|
148
198
|
## add support for ordinals.com api txt (headers format)
|
199
|
+
##
|
200
|
+
## todo/fix: move to importer!!! - why? why not?
|
149
201
|
|
150
202
|
|
151
203
|
def self.create_from_api( data ) create( _parse_api( data )); end
|
data/lib/ordlite/schema.rb
CHANGED
@@ -56,6 +56,7 @@ create_table :inscribes, :id => :string do |t|
|
|
56
56
|
|
57
57
|
## "timestamp": "2023-06-01 05:00:57 UTC"
|
58
58
|
## or use date_utc ???
|
59
|
+
## or change to t.integer AND timestamp or time or epoch(time) - why? why not?
|
59
60
|
t.datetime :date, null: false
|
60
61
|
|
61
62
|
##
|
@@ -99,8 +100,8 @@ create_table :blobs, :id => :string do |t|
|
|
99
100
|
## t.string :id, null: false, index: { unique: true, name: 'blob_uuids' }
|
100
101
|
|
101
102
|
t.binary :content, null: false
|
102
|
-
t.string :sha256 ## sha256 hash
|
103
|
-
t.string :md5 ## md5 hash - add why? why not?
|
103
|
+
t.string :sha256 ## sha256 hash as hexstring
|
104
|
+
t.string :md5 ## md5 hash as hexstring - add why? why not?
|
104
105
|
|
105
106
|
## timestamp last
|
106
107
|
t.timestamps
|
@@ -193,23 +194,5 @@ end # block Schema.define
|
|
193
194
|
|
194
195
|
end # method up
|
195
196
|
end # class CreateDb
|
196
|
-
|
197
|
-
###
|
198
|
-
# migrations helpers
|
199
|
-
class AddGeneratives
|
200
|
-
|
201
|
-
def up
|
202
|
-
ActiveRecord::Schema.define do
|
203
|
-
create_table :generatives, :id => :string do |t|
|
204
|
-
t.string :factory_id, null: false
|
205
|
-
t.string :g, null: false ## use space separated numbers - why? why not?
|
206
|
-
t.binary :content ### optional for now - why? why not?
|
207
|
-
|
208
|
-
## timestamp last
|
209
|
-
t.timestamps
|
210
|
-
end
|
211
|
-
end # block Schema.define
|
212
|
-
end # method up
|
213
|
-
end # class AddGeneratives
|
214
197
|
|
215
198
|
end # module OrdDb
|
data/lib/ordlite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ordlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ordinals
|