ordlite 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 349d70aaa528cdced0835181ca83ad5bb8815982bc60bc7f9d5535095131b322
4
- data.tar.gz: 505f8f222ea148ca87f84080696cc0ec8d369a1a285aa50270ce8db6632ace96
3
+ metadata.gz: 238e3e5f3913821c8f0a70bdedb444deeea65da4ecdb5827f239b3b4a682a151
4
+ data.tar.gz: d01946f571d34b1b29ca7fe0216898f31fddc75e818d07300129af5d1a808c5e
5
5
  SHA512:
6
- metadata.gz: 4a1ecae2ec91d531ae6ff660dea7861243569f7c2009cbf48315e88a406ddbc0b9cdf91a8b29291b8e64e2f99d5051188662356a3bbf70efd394d4f7e7f13cfa
7
- data.tar.gz: 50cc3f57b2cade5086a12a9c459469a991a667fe9b30431f2b2f6c957c1462430a41bbd6e2e50b635631668d4f6f3ef70aa54a6f6ec7a9d812a17c920b1031f2
6
+ metadata.gz: 1545c336ad9d22d92235bbe7160b3224a311cf5dd06b8a944d18d5d2e80c62a24f342be5ed3b295dd9b99cddd7654f931893f811a9571ef80688956cdff27178
7
+ data.tar.gz: 7300eb7a35ddcf56a41e10cdbc8844d81f8340147b18125d62a528d1eb27e4f8854e72ff70ec3858723ce2da99a3105b80f4414ec1706a593e81915b1aec9fb5
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.1.1 / 2023-07-01
1
+ ### 0.1.2 / 2023-07-02
2
2
  ### 0.0.1 / 2023-07-01
3
3
 
4
4
  * Everything is new. First release
data/README.md CHANGED
@@ -11,13 +11,158 @@ ordlite - ordinals inscription (on bitcoin & co) database let's you query via sq
11
11
 
12
12
 
13
13
 
14
+ ## SQL Database Model
15
+
16
+ Insribes • Blobs
17
+
18
+
19
+ Table Inscribes
20
+
21
+ ``` sql
22
+ CREATE TABLE "inscribes" (
23
+ "id" varchar NOT NULL PRIMARY KEY,
24
+ "num" integer NOT NULL,
25
+ "bytes" integer NOT NULL,
26
+ "content_type" varchar NOT NULL,
27
+ "date" datetime(6) NOT NULL,
28
+ "sat" integer NOT NULL,
29
+ "block" integer NOT NULL,
30
+ "fee" integer NOT NULL,
31
+ "tx" varchar NOT NULL,
32
+ "offset" integer NOT NULL,
33
+ "address" varchar NOT NULL,
34
+ "output" varchar NOT NULL,
35
+ "value" integer NOT NULL,
36
+ )
37
+ ```
38
+
39
+ Table Blobs
40
+
41
+ ``` sql
42
+ CREATE TABLE "blobs" (
43
+ "id" varchar NOT NULL PRIMARY KEY,
44
+ "content" blob NOT NULL,
45
+ )
46
+ ```
47
+
48
+
14
49
  ## Usage
15
50
 
16
- To be done
17
51
 
52
+ ### Step 0: Setup Databae
53
+
54
+ ``` ruby
55
+ require 'ordlite'
56
+
57
+ OrdDb.connect( adapter: 'sqlite3',
58
+ database: './ord.db' )
59
+
60
+ OrdDb.create_all # build table schema
61
+
62
+ puts
63
+ puts " #{Inscribe.count} inscribe(s)"
64
+ puts " #{Blob.count} blob(s)"
65
+
66
+ #=> 0 inscribe(s)
67
+ #=> 0 blob(s)
68
+ ```
69
+
70
+
71
+
72
+
73
+ ### Example No 1 - Query Ordgen Deploy / Mint Inscriptions
74
+
75
+ ``` ruby
76
+ require 'ordlite'
77
+
78
+
79
+ OrdDb.connect( adapter: 'sqlite3',
80
+ database: './ord.db' )
81
+
82
+
83
+ ####################
84
+ ## query for deploy candidates
85
+ ##
86
+ ## e.g. sql where clause like
87
+ ## content LIKE '%deploy%'
88
+ ## AND ( content LIKE '%orc-721%'
89
+ ## OR content LIKE '%og%')
90
+ ##
91
+
92
+ deploys = Inscribe.deploys
93
+ puts " #{deploys.size} deploy candidate(s)"
94
+
95
+ deploys.each_with_index do |rec,i|
96
+ puts "==> deploy #{i} - num #{rec.num} - #{rec.bytes} bytes - #{rec.date}"
97
+ puts rec.content
98
+ end
99
+
100
+
101
+ punks_deploys = Inscribe.deploys_by( slug: 'diypunks')
102
+ puts " #{punks_deploys.size} deploy candidate(s)"
103
+
104
+
105
+
106
+ #######################
107
+ ## query for mint candidates
108
+ ##
109
+ ## e.g. sql where clause like
110
+ ## content LIKE '%mint%'
111
+ ## AND ( content LIKE '%orc-721%'
112
+ ## OR content LIKE '%og%')
113
+
114
+ mints = Inscribe.mints
115
+ puts " #{mints.size} mint candidate(s)"
116
+
117
+ ## print last hundred mint candidates
118
+ mints[-100,100].each_with_index do |rec,i|
119
+ puts "==> mint #{i} - num #{rec.num} - #{rec.bytes} bytes - #{rec.date}"
120
+ puts rec.content
121
+ end
122
+
123
+
124
+ phunks_mints = Inscribe.mints_by( slug: 'diyphunks')
125
+ puts " #{phunks_mints.size} mint candidate(s)"
126
+
127
+
128
+ puts " #{deploys.size} deploy candidate(s)"
129
+ puts " #{mints.size} mint candidate(s)"
130
+
131
+ #=> 123 deploy candidate(s)
132
+ #=> 7453 mint candidate(s)
133
+ ```
134
+
135
+
136
+
137
+
138
+ ### Bonus: Import (Cached) Inscription Datafiles (& Content)
139
+
140
+ Let's import all cached
141
+ inscriptions metadata datafiles (& content)
142
+ from [/ordinals.cache](https://github.com/ordbase/ordinals.cache)
143
+ into an (sql) database e.g. `ord.db`:
144
+
145
+
146
+ ``` ruby
147
+ require 'ordlite'
148
+
149
+ OrdDb.connect( adapter: 'sqlite3',
150
+ database: './ord.db' )
151
+
152
+ OrdDb.create_all # build table schema
153
+
154
+ cache_dir = './ordinals.cache/btc'
155
+ cache = OrdDb::Cache.new( cache_dir )
156
+ cache.import_all
18
157
 
19
158
 
159
+ puts
160
+ puts " #{Inscribe.count} inscribe(s)"
161
+ puts " #{Blob.count} blob(s)"
20
162
 
163
+ #=> 8505 inscribe(s)
164
+ #=> 7611 blob(s)
165
+ ```
21
166
 
22
167
 
23
168
  ## License
@@ -4,6 +4,56 @@ module OrdDb
4
4
 
5
5
  class Inscribe < ActiveRecord::Base
6
6
  has_one :blob, foreign_key: 'id'
7
+
8
+ def content
9
+ ## convernience helper
10
+ ## forward to blob.content
11
+ blob.content
12
+ end
13
+
14
+ ################################
15
+ ### scope like helpers
16
+ def self.deploys
17
+ where_clause =<<SQL
18
+ content LIKE '%deploy%'
19
+ AND ( content LIKE '%orc-721%'
20
+ OR content LIKE '%og%')
21
+ SQL
22
+
23
+ joins(:blob).where( where_clause ).order( 'num' )
24
+ end
25
+
26
+ def self.deploys_by( slug: )
27
+ where_clause =<<SQL
28
+ content LIKE '%deploy%'
29
+ AND ( content LIKE '%orc-721%'
30
+ OR content LIKE '%og%')
31
+ AND content LIKE '%#{slug}%'
32
+ SQL
33
+
34
+ joins(:blob).where( where_clause ).order( 'num' )
35
+ end
36
+
37
+ def self.mints
38
+ where_clause =<<SQL
39
+ content LIKE '%mint%'
40
+ AND ( content LIKE '%orc-721%'
41
+ OR content LIKE '%og%')
42
+ SQL
43
+
44
+ joins(:blob).where( where_clause ).order( 'num' )
45
+ end
46
+
47
+ def self.mints_by( slug: )
48
+ where_clause =<<SQL
49
+ content LIKE '%mint%'
50
+ AND ( content LIKE '%orc-721%'
51
+ OR content LIKE '%og%')
52
+ AND content LIKE '%#{slug}%'
53
+ SQL
54
+
55
+ joins(:blob).where( where_clause ).order( 'num' )
56
+ end
7
57
  end # class Inscribe
8
58
 
9
59
  end # module Model
@@ -4,7 +4,7 @@ module Ordlite
4
4
  # sync version w/ sport.db n friends - why? why not?
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 1
7
- PATCH = 1
7
+ PATCH = 2
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
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.1.1
4
+ version: 0.1.2
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-07-01 00:00:00.000000000 Z
11
+ date: 2023-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord