scribelite 0.0.1 → 0.2.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 -0
- data/Manifest.txt +5 -0
- data/README.md +79 -1
- data/Rakefile +12 -4
- data/lib/scribelite/models/forward.rb +24 -0
- data/lib/scribelite/models/scribe.rb +189 -0
- data/lib/scribelite/models/tx.rb +18 -0
- data/lib/scribelite/schema.rb +75 -0
- data/lib/scribelite/version.rb +19 -0
- data/lib/scribelite.rb +143 -1
- metadata +122 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0608ffa940a6f65b4432a6e8e494ec2213e20a6fb661e15eafb9f0408f1175be'
|
4
|
+
data.tar.gz: 5b019fbe73890c1b20a5c4106a617e2c573431e805b47825fb056f7bd50449aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a363643f683a32c1ccbd04448d790b6582f5ccc7d8d3176ab65506ff92d826a5b54e37b41add46bb8c8b577a8f76aa9d8ee7800a7d946aa7cf5ce9802fb283b
|
7
|
+
data.tar.gz: 491db0258ff4a4dc27974f9e3e8e8147a9437690dfdd2c30bf8d81b8710aee0f7ee4a119cd3657b6d48f1cc3399570e4787ef9fbdc87d17ec4f4115acb79d1e7
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Inscription / Inscribe (Ethscription Calldata) SQL Database
|
1
|
+
# Scribelite - Inscription / Inscribe (Ethscription Calldata) SQL Database
|
2
2
|
|
3
3
|
scribelite - inscription / inscribe (ethscription calldata) database for ethereum & co; let's you query via sql and more
|
4
4
|
|
@@ -19,11 +19,89 @@ See [Introducing Ethscriptions - A new way of creating and sharing digital artif
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
+
The work-in-progess database schema looks like:
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
ActiveRecord::Schema.define do
|
26
|
+
|
27
|
+
create_table :scribes, :id => :string do |t|
|
28
|
+
t.integer :num, null: false, index: { unique: true, name: 'scribe_nums' }
|
29
|
+
t.integer :bytes
|
30
|
+
t.string :content_type
|
31
|
+
## add allow duplicate opt-in protocol flag e.g. esip6
|
32
|
+
t.boolean :duplicate ## allows duplicates flag
|
33
|
+
t.boolean :flagged, null: false, default: false ## censored flag / removed on request
|
34
|
+
## move sha to tx - why? why not?
|
35
|
+
t.string :sha, null: false ## sha hash as hexstring (but no leading 0)
|
36
|
+
end
|
37
|
+
|
38
|
+
create_table :txs, :id => :string do |t|
|
39
|
+
t.binary :data # , null: false
|
40
|
+
t.datetime :date, null: false
|
41
|
+
t.integer :block, null: false
|
42
|
+
t.integer :idx, null: false ## transaction index (number)
|
43
|
+
|
44
|
+
t.string :from, null: false
|
45
|
+
t.string :to, null: false
|
46
|
+
|
47
|
+
t.integer :fee
|
48
|
+
t.integer :value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
and to setup use it like:
|
55
|
+
|
56
|
+
``` ruby
|
57
|
+
require 'scribelite'
|
58
|
+
|
59
|
+
ScribeDb.connect( adapter: 'sqlite3',
|
60
|
+
database: './scribe.db' )
|
61
|
+
|
62
|
+
ScribeDb.create_all ## build schema
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
and to query use it like:
|
67
|
+
|
68
|
+
``` ruby
|
69
|
+
require 'scribelite'
|
70
|
+
|
71
|
+
ScribeDb.open( './scribe.db' )
|
72
|
+
|
73
|
+
puts
|
74
|
+
puts " #{Scribe.count} scribe(s)"
|
75
|
+
puts " #{Tx.count} tx(s)"
|
76
|
+
|
77
|
+
|
78
|
+
## how many flagged in top 100?
|
79
|
+
limit = 100
|
80
|
+
|
81
|
+
flagged_count = Scribe.order( :num ).limit(limit).where( flagged: true ).count
|
82
|
+
pp flagged_count #=> 75 !!!!!!!!!
|
83
|
+
unflagged_count = Scribe.order( :num).limit(limit).where( flagged: false ).count
|
84
|
+
pp unflagged_count #=> 25
|
85
|
+
|
86
|
+
|
87
|
+
Scribe.order( :num ).limit(limit).each do |scribe|
|
88
|
+
if scribe.flagged?
|
89
|
+
print " xx "
|
90
|
+
else
|
91
|
+
print "==> "
|
92
|
+
end
|
93
|
+
print "#{scribe.num} / #{scribe.content_type} - #{scribe.tx.date} @ #{scribe.tx.block}"
|
94
|
+
print "\n"
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
|
22
99
|
To be continued...
|
23
100
|
|
24
101
|
|
25
102
|
|
26
103
|
|
104
|
+
|
27
105
|
## Bonus - More Blockchain (Crypto) Tools, Libraries & Scripts In Ruby
|
28
106
|
|
29
107
|
See [**/blockchain**](https://github.com/rubycocos/blockchain)
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'hoe'
|
2
|
-
|
2
|
+
require './lib/scribelite/version.rb'
|
3
3
|
|
4
4
|
|
5
5
|
Hoe.spec 'scribelite' do
|
6
|
-
self.version =
|
6
|
+
self.version = Scribelite::VERSION
|
7
7
|
|
8
|
-
self.summary = "scribelite - inscription / inscribe (ethscription calldata) database for ethereum & co; let's you query via sql and more"
|
8
|
+
self.summary = "scribelite gem - inscription / inscribe (ethscription calldata) database for ethereum & co; let's you query via sql and more"
|
9
9
|
self.description = summary
|
10
10
|
|
11
11
|
self.urls = { home: 'https://github.com/s6ruby/rubidity' }
|
@@ -18,7 +18,15 @@ Hoe.spec 'scribelite' do
|
|
18
18
|
self.history_file = 'CHANGELOG.md'
|
19
19
|
|
20
20
|
self.extra_deps = [
|
21
|
-
['ethscribe'],
|
21
|
+
['ethscribe'],
|
22
|
+
['calldata'], ## todo - check if included via ethscribe in the future?
|
23
|
+
['activerecord'],
|
24
|
+
['activerecord-utils'],
|
25
|
+
['logutils'],
|
26
|
+
['logutils-activerecord'],
|
27
|
+
['props'],
|
28
|
+
['props-activerecord'],
|
29
|
+
['sqlite3'],
|
22
30
|
]
|
23
31
|
|
24
32
|
self.licenses = ['Public Domain']
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
### forward references
|
3
|
+
## require first to resolve circular references
|
4
|
+
|
5
|
+
module ScribeDb
|
6
|
+
module Model
|
7
|
+
|
8
|
+
#############
|
9
|
+
# ConfDb
|
10
|
+
Prop = ConfDb::Model::Prop
|
11
|
+
|
12
|
+
|
13
|
+
class Scribe < ActiveRecord::Base ; end
|
14
|
+
class Tx < ActiveRecord::Base ; end
|
15
|
+
|
16
|
+
|
17
|
+
end # module Model
|
18
|
+
|
19
|
+
# note: convenience alias for Model
|
20
|
+
# lets you use include ScribeDb::Models
|
21
|
+
Models = Model
|
22
|
+
end # module ScribeDb
|
23
|
+
|
24
|
+
|
@@ -0,0 +1,189 @@
|
|
1
|
+
|
2
|
+
module ScribeDb
|
3
|
+
module Model
|
4
|
+
|
5
|
+
class Scribe < ActiveRecord::Base
|
6
|
+
has_one :tx, foreign_key: 'id'
|
7
|
+
|
8
|
+
## convernience helper
|
9
|
+
## forward to blob.content
|
10
|
+
## blob.content - encoding is BINARY (ASCII-7BIT)
|
11
|
+
## blob.text - force_encoding is UTF-8 (return a copy)
|
12
|
+
# def content() blob.content; end
|
13
|
+
# def text() blob.text; end
|
14
|
+
|
15
|
+
|
16
|
+
################################
|
17
|
+
### scope like helpers
|
18
|
+
def self.png() where( content_type: 'image/png' ); end
|
19
|
+
def self.gif() where( content_type: 'image/gif' ); end
|
20
|
+
def self.jpg() where( content_type: 'image/jpeg' ); end
|
21
|
+
def self.webp() where( content_type: 'image/webp' ); end
|
22
|
+
def self.svg() where( content_type: 'image/svg+xml' ); end
|
23
|
+
def self.avif() where( content_type: 'image/avif' ); end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
alias_method :jpeg, :jpg
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.image
|
30
|
+
## change to/or add alias e.g. image/images - why? why not
|
31
|
+
where( content_type: [
|
32
|
+
'image/png',
|
33
|
+
'image/jpeg',
|
34
|
+
'image/gif',
|
35
|
+
'image/webp',
|
36
|
+
'image/svg+xml',
|
37
|
+
'image/avif',
|
38
|
+
])
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.html
|
42
|
+
where( content_type: [
|
43
|
+
'text/html;charset=utf-8',
|
44
|
+
'text/html',
|
45
|
+
])
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.js
|
49
|
+
where( content_type: [
|
50
|
+
'text/javascript',
|
51
|
+
'application/javascript',
|
52
|
+
])
|
53
|
+
end
|
54
|
+
|
55
|
+
class << self
|
56
|
+
alias_method :javascript, :js
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.text
|
60
|
+
## change to/or add alias e.g. text/texts - why? why not
|
61
|
+
## include html or svg in text-only inscription - why? why not?
|
62
|
+
## include markdown in text-only inscription - why? why not?
|
63
|
+
## make content_type lower case with lower() - why? why not?
|
64
|
+
where( content_type: [
|
65
|
+
'text/plain',
|
66
|
+
'text/plain;charset=utf-8',
|
67
|
+
'text/plain;charset=us-ascii',
|
68
|
+
'application/json',
|
69
|
+
])
|
70
|
+
end
|
71
|
+
|
72
|
+
=begin
|
73
|
+
def self.search( q ) ## "full-text" search helper
|
74
|
+
## rename to text_search - why? why not?
|
75
|
+
## auto-sort by num - why? why not?
|
76
|
+
joins(:blob).text.where( "content LIKE '%#{q}%'" ).order('num')
|
77
|
+
end
|
78
|
+
=end
|
79
|
+
|
80
|
+
def self.sub1k() where( 'num < 1000' ); end
|
81
|
+
def self.sub2k() where( 'num < 2000' ); end
|
82
|
+
def self.sub10k() where( 'num < 10000' ); end
|
83
|
+
def self.sub20k() where( 'num < 20000' ); end
|
84
|
+
def self.sub100k() where( 'num < 100000' ); end
|
85
|
+
def self.sub1m() where( 'num < 1000000' ); end
|
86
|
+
def self.sub2m() where( 'num < 2000000' ); end
|
87
|
+
def self.sub10m() where( 'num < 10000000' ); end
|
88
|
+
def self.sub20m() where( 'num < 20000000' ); end
|
89
|
+
def self.sub21m() where( 'num < 21000000' ); end
|
90
|
+
|
91
|
+
|
92
|
+
def self.largest
|
93
|
+
order( 'bytes DESC' )
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.content_type_counts
|
97
|
+
group( 'content_type' )
|
98
|
+
.order( Arel.sql( 'COUNT(*) DESC, content_type')).count
|
99
|
+
end
|
100
|
+
|
101
|
+
class << self
|
102
|
+
alias_method :biggest, :largest
|
103
|
+
alias_method :counts_by_content_type, :content_type_counts
|
104
|
+
end
|
105
|
+
|
106
|
+
###
|
107
|
+
# instance methods
|
108
|
+
def extname
|
109
|
+
## map mime type to file extname
|
110
|
+
## see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
|
111
|
+
## for real-world usage, see https://dune.com/dgtl_assets/bitcoin-ordinals-analysis
|
112
|
+
## https://github.com/casey/ord/blob/master/src/media.rs
|
113
|
+
|
114
|
+
if content_type.start_with?( 'text/plain' )
|
115
|
+
'.txt'
|
116
|
+
elsif content_type.start_with?( 'text/markdown' )
|
117
|
+
'.md'
|
118
|
+
elsif content_type.start_with?( 'text/html' )
|
119
|
+
'.html'
|
120
|
+
elsif content_type.start_with?( 'text/javascript' ) ||
|
121
|
+
content_type.start_with?( 'application/javascript' )
|
122
|
+
## note: application/javascript is considered bad practice/legacy
|
123
|
+
'.js'
|
124
|
+
elsif content_type.start_with?( 'image/png' )
|
125
|
+
## Portable Network Graphics (PNG)
|
126
|
+
'.png'
|
127
|
+
elsif content_type.start_with?( 'image/jpeg' )
|
128
|
+
## Joint Photographic Expert Group image (JPEG)
|
129
|
+
'.jpg' ## use jpeg - why? why not?
|
130
|
+
elsif content_type.start_with?( 'image/webp' )
|
131
|
+
## Web Picture format (WEBP)
|
132
|
+
'.webp' ## note: no three-letter extension available
|
133
|
+
elsif content_type.start_with?( 'image/svg' )
|
134
|
+
## Scalable Vector Graphics (SVG)
|
135
|
+
'.svg'
|
136
|
+
elsif content_type.start_with?( 'image/gif' )
|
137
|
+
## Graphics Interchange Format (GIF)
|
138
|
+
'.gif'
|
139
|
+
elsif content_type.start_with?( 'image/avif' )
|
140
|
+
## AV1 Image File Format (AVIF)
|
141
|
+
'.avif'
|
142
|
+
elsif content_type.start_with?( 'application/epub' )
|
143
|
+
'.epub'
|
144
|
+
elsif content_type.start_with?( 'application/pdf' )
|
145
|
+
'.pdf'
|
146
|
+
elsif content_type.start_with?( 'application/json' )
|
147
|
+
'.json'
|
148
|
+
elsif content_type.start_with?( 'application/pgp-signature' )
|
149
|
+
'.sig'
|
150
|
+
elsif content_type.start_with?( 'audio/mpeg' )
|
151
|
+
'.mp3'
|
152
|
+
elsif content_type.start_with?( 'audio/midi' )
|
153
|
+
'.midi'
|
154
|
+
elsif content_type.start_with?( 'video/mp4' )
|
155
|
+
'.mp4'
|
156
|
+
elsif content_type.start_with?( 'video/webm' )
|
157
|
+
'.wepm'
|
158
|
+
elsif content_type.start_with?( 'audio/mod' )
|
159
|
+
## is typo? possible? only one inscription in 20m?
|
160
|
+
'.mod' ## check/todo/fix if is .wav??
|
161
|
+
else
|
162
|
+
puts "!! ERROR - no file extension configured for content type >#{content_type}<; sorry:"
|
163
|
+
pp self
|
164
|
+
exit 1
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
=begin
|
169
|
+
def export_path ## default export path
|
170
|
+
numstr = "%08d" % num ### e.g. 00000001
|
171
|
+
"./tmp/#{numstr}#{extname}"
|
172
|
+
end
|
173
|
+
def export( path=export_path )
|
174
|
+
if blob
|
175
|
+
write_blob( path, blob.content )
|
176
|
+
else
|
177
|
+
## todo/fix: raise exception - no content
|
178
|
+
puts "!! ERROR - inscribe has no content (blob); sorry:"
|
179
|
+
pp self
|
180
|
+
exit 1
|
181
|
+
end
|
182
|
+
end
|
183
|
+
=end
|
184
|
+
|
185
|
+
end # class Scribe
|
186
|
+
|
187
|
+
end # module Model
|
188
|
+
end # module ScribeDb
|
189
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module ScribeDb
|
3
|
+
module Model
|
4
|
+
|
5
|
+
class Tx < ActiveRecord::Base
|
6
|
+
self.table_name = 'txs' ## note auto-infers txes change to txs
|
7
|
+
|
8
|
+
belongs_to :inscribe, foreign_key: 'id'
|
9
|
+
=begin
|
10
|
+
def text
|
11
|
+
content.force_encoding(Encoding::UTF_8)
|
12
|
+
end
|
13
|
+
=end
|
14
|
+
end # class Tx
|
15
|
+
|
16
|
+
end # module Model
|
17
|
+
end # module ScribeDb
|
18
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module ScribeDb
|
4
|
+
|
5
|
+
class CreateDb
|
6
|
+
|
7
|
+
def up
|
8
|
+
|
9
|
+
ActiveRecord::Schema.define do
|
10
|
+
|
11
|
+
create_table :scribes, :id => :string do |t|
|
12
|
+
## "id": "0a3a4dbf6630338bc4df8e36bd081f8f7d2dee9441131cb03a18d43eb4882d5ci0",
|
13
|
+
## note: change to uuid (universally unique id) - why? why not?
|
14
|
+
## id gets used by row_id (internal orm db machinery) and is int
|
15
|
+
## t.string :uuid, null: false, index: { unique: true, name: 'scribe_uuids' }
|
16
|
+
|
17
|
+
## "title": "Inscription 10371414",
|
18
|
+
## note: use num/no. from title only - why? why not?
|
19
|
+
t.integer :num, null: false, index: { unique: true, name: 'scribe_nums' }
|
20
|
+
|
21
|
+
## "content length": "85 bytes",
|
22
|
+
## note: extract bytes as integer!!!
|
23
|
+
## change to bytes - why? why not?
|
24
|
+
t.integer :bytes
|
25
|
+
## "content type": "text/plain;charset=utf-8",
|
26
|
+
## note: make sure always lower/down case!!!
|
27
|
+
t.string :content_type
|
28
|
+
|
29
|
+
## add allow duplicate opt-in protocol flag e.g. esip6
|
30
|
+
t.boolean :duplicate ## allows duplicates flag - make duplicate the default - why? why not?
|
31
|
+
t.boolean :flagged, null: false, default: false ## censored flag / removed on request
|
32
|
+
|
33
|
+
## move sha to tx - why? why not?
|
34
|
+
t.string :sha # , null: false ## sha hash as hexstring
|
35
|
+
|
36
|
+
## timestamp last
|
37
|
+
t.timestamps
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
## change to tx/txs or txn/txns - why? why not?
|
42
|
+
|
43
|
+
create_table :txs, :id => :string do |t|
|
44
|
+
## "id": "0a3a4dbf6630338bc4df8e36bd081f8f7d2dee9441131cb03a18d43eb4882d5ci0",
|
45
|
+
## note: change to uuid (universally unique id) - why? why not?
|
46
|
+
## id gets used by row_id (internal orm db machinery) and is int
|
47
|
+
## t.string :id, null: false, index: { unique: true, name: 'blob_uuids' }
|
48
|
+
|
49
|
+
t.binary :data # , null: false
|
50
|
+
|
51
|
+
## "timestamp": "2023-06-01 05:00:57 UTC"
|
52
|
+
## or use date_utc ???
|
53
|
+
## or change to t.integer AND timestamp or time or epoch(time) - why? why not?
|
54
|
+
t.datetime :date, null: false
|
55
|
+
|
56
|
+
t.integer :block, null: false
|
57
|
+
t.integer :idx, null: false ## transaction index (number)
|
58
|
+
|
59
|
+
t.string :from, null: false
|
60
|
+
t.string :to, null: false
|
61
|
+
|
62
|
+
t.integer :fee
|
63
|
+
t.integer :value
|
64
|
+
|
65
|
+
|
66
|
+
## timestamp last
|
67
|
+
t.timestamps
|
68
|
+
end
|
69
|
+
|
70
|
+
end # block Schema.define
|
71
|
+
|
72
|
+
end # method up
|
73
|
+
end # class CreateDb
|
74
|
+
|
75
|
+
end # module ScribeDb
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module Scribelite
|
3
|
+
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
4
|
+
MINOR = 2
|
5
|
+
PATCH = 0
|
6
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
7
|
+
|
8
|
+
def self.version
|
9
|
+
VERSION
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.banner
|
13
|
+
"scribelite/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in >#{root}<"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.root
|
17
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
18
|
+
end
|
19
|
+
end
|
data/lib/scribelite.rb
CHANGED
@@ -1,4 +1,146 @@
|
|
1
1
|
|
2
|
+
# core and stlibs
|
3
|
+
require 'ethscribe' ## will pull-in cocos & friends
|
4
|
+
require 'calldata'
|
2
5
|
|
3
|
-
|
6
|
+
|
7
|
+
require 'logger' # Note: use for ActiveRecord::Base.logger -- remove/replace later w/ LogUtils::Logger ???
|
8
|
+
require 'date' ## check if date & datetime required ??
|
9
|
+
|
10
|
+
|
11
|
+
# 3rd party gems / libs
|
12
|
+
require 'props' # see github.com/rubylibs/props
|
13
|
+
require 'logutils' # see github.com/rubylibs/logutils
|
14
|
+
|
15
|
+
|
16
|
+
require 'active_record' ## todo: add sqlite3? etc.
|
17
|
+
|
18
|
+
## add more activerecords addons/utils
|
19
|
+
# require 'tagutils'
|
20
|
+
require 'activerecord/utils'
|
21
|
+
require 'props/activerecord' # includes ConfDb (ConfDb::Model::Prop, etc.)
|
22
|
+
require 'logutils/activerecord' # includes LogDb (LogDb::Model::Log, etc.)
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
# our own code
|
27
|
+
require_relative 'scribelite/version' # always goes first
|
28
|
+
|
29
|
+
require_relative 'scribelite/models/forward'
|
30
|
+
|
31
|
+
require_relative 'scribelite/models/scribe'
|
32
|
+
require_relative 'scribelite/models/tx'
|
33
|
+
|
34
|
+
|
35
|
+
require_relative 'scribelite/schema'
|
36
|
+
|
37
|
+
# require_relative 'cache'
|
38
|
+
# require_relative 'importer' ## note: require (soft dep) ordinals gems!!!
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
module ScribeDb
|
44
|
+
|
45
|
+
def self.create
|
46
|
+
CreateDb.new.up
|
47
|
+
ConfDb::Model::Prop.create!( key: 'db.schema.scribe.version',
|
48
|
+
value: Scribelite::VERSION )
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.create_all
|
52
|
+
LogDb.create # add logs table
|
53
|
+
ConfDb.create # add props table
|
54
|
+
ScribeDb.create
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.auto_migrate!
|
58
|
+
### todo/fix:
|
59
|
+
## check props table and versions!!!!!
|
60
|
+
|
61
|
+
# first time? - auto-run db migratation, that is, create db tables
|
62
|
+
unless LogDb::Model::Log.table_exists?
|
63
|
+
LogDb.create # add logs table
|
64
|
+
end
|
65
|
+
|
66
|
+
unless ConfDb::Model::Prop.table_exists?
|
67
|
+
ConfDb.create # add props table
|
68
|
+
end
|
69
|
+
|
70
|
+
unless ScribeDb::Model::Scribe.table_exists?
|
71
|
+
ScribeDb.create
|
72
|
+
end
|
73
|
+
end # method auto_migrate!
|
74
|
+
|
75
|
+
|
76
|
+
def self.open( database='./scribe.db' ) ## convenience helper for sqlite only
|
77
|
+
connect( adapter: 'sqlite3',
|
78
|
+
database: database )
|
79
|
+
|
80
|
+
## build schema if database new/empty
|
81
|
+
auto_migrate!
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
def self.connect( config={} )
|
87
|
+
|
88
|
+
if config.empty?
|
89
|
+
puts "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
|
90
|
+
|
91
|
+
### change default to ./scribe.db ?? why? why not?
|
92
|
+
db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///scribe.db' )
|
93
|
+
|
94
|
+
if db.scheme == 'postgres'
|
95
|
+
config = {
|
96
|
+
adapter: 'postgresql',
|
97
|
+
host: db.host,
|
98
|
+
port: db.port,
|
99
|
+
username: db.user,
|
100
|
+
password: db.password,
|
101
|
+
database: db.path[1..-1],
|
102
|
+
encoding: 'utf8'
|
103
|
+
}
|
104
|
+
else # assume sqlite3
|
105
|
+
config = {
|
106
|
+
adapter: db.scheme, # sqlite3
|
107
|
+
database: db.path[1..-1] # scribe.db (NB: cut off leading /, thus 1..-1)
|
108
|
+
}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
puts "Connecting to db using settings: "
|
113
|
+
pp config
|
114
|
+
ActiveRecord::Base.establish_connection( config )
|
115
|
+
# ActiveRecord::Base.logger = Logger.new( STDOUT )
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def self.setup_in_memory_db
|
120
|
+
|
121
|
+
# Database Setup & Config
|
122
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
123
|
+
## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
|
124
|
+
|
125
|
+
self.connect( adapter: 'sqlite3',
|
126
|
+
database: ':memory:' )
|
127
|
+
|
128
|
+
## build schema
|
129
|
+
ScribeDb.create_all
|
130
|
+
end # setup_in_memory_db (using SQLite :memory:)
|
131
|
+
|
132
|
+
end # module ScribeDb
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
## add convenience helpers
|
140
|
+
Scribe = ScribeDb::Model::Scribe
|
141
|
+
Tx = ScribeDb::Model::Tx
|
142
|
+
|
143
|
+
|
144
|
+
# say hello
|
145
|
+
puts Scribelite.banner ## if defined?($RUBYCOCOS_DEBUG) && $RUBCOCOS_DEBUG
|
4
146
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scribelite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.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-11-
|
11
|
+
date: 2023-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ethscribe
|
@@ -24,6 +24,118 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: calldata
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord-utils
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: logutils
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: logutils-activerecord
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: props
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: props-activerecord
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sqlite3
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
27
139
|
- !ruby/object:Gem::Dependency
|
28
140
|
name: rdoc
|
29
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,7 +170,7 @@ dependencies:
|
|
58
170
|
- - "~>"
|
59
171
|
- !ruby/object:Gem::Version
|
60
172
|
version: '4.0'
|
61
|
-
description: scribelite - inscription / inscribe (ethscription calldata) database
|
173
|
+
description: scribelite gem - inscription / inscribe (ethscription calldata) database
|
62
174
|
for ethereum & co; let's you query via sql and more
|
63
175
|
email: gerald.bauer@gmail.com
|
64
176
|
executables: []
|
@@ -73,6 +185,11 @@ files:
|
|
73
185
|
- README.md
|
74
186
|
- Rakefile
|
75
187
|
- lib/scribelite.rb
|
188
|
+
- lib/scribelite/models/forward.rb
|
189
|
+
- lib/scribelite/models/scribe.rb
|
190
|
+
- lib/scribelite/models/tx.rb
|
191
|
+
- lib/scribelite/schema.rb
|
192
|
+
- lib/scribelite/version.rb
|
76
193
|
homepage: https://github.com/s6ruby/rubidity
|
77
194
|
licenses:
|
78
195
|
- Public Domain
|
@@ -97,6 +214,6 @@ requirements: []
|
|
97
214
|
rubygems_version: 3.4.10
|
98
215
|
signing_key:
|
99
216
|
specification_version: 4
|
100
|
-
summary: scribelite - inscription / inscribe (ethscription calldata) database
|
101
|
-
ethereum & co; let's you query via sql and more
|
217
|
+
summary: scribelite gem - inscription / inscribe (ethscription calldata) database
|
218
|
+
for ethereum & co; let's you query via sql and more
|
102
219
|
test_files: []
|