ordlite 0.0.1 → 0.1.0

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: bab34acd6766a0c9219ceb16dc38ca59bf19b33b7de6a54aed644b5680ec5563
4
- data.tar.gz: 62411ce2e9563bb9387a1f1fe72b5bb53f408a644a10f846a6ec4664647282d4
3
+ metadata.gz: 1d227087815f81d4a3bc1791e2fd34639074c8000568ca1c378c865d5450e39a
4
+ data.tar.gz: c3697c7d069e85ade6dd427918796d5bf6cd302475299f5eb080287c80536508
5
5
  SHA512:
6
- metadata.gz: edad4aa42248de21b75ba2c7a7d3a372fb23c671b1ee38d1f7fcb971a3f3f86afb8f0c532988091f528024cfc8e23b3f46e2c53c1995f2bb910f1de4dada62e3
7
- data.tar.gz: 3a4a42f490533813a585e86e5edc7333462cb92684df9b0b761c2a44a0590dfac8acae49c6fcc630f785fe11bcb18b9ee340e169c90aced3e1d469539048cd21
6
+ metadata.gz: 0b7d753c4767407663ff2e29f2eaf2efe2689e0283ae332ada7404e3fc797678664a91d285e79cb09abf3f73675615f729c6e653093d9d895f710def43954503
7
+ data.tar.gz: b85fd1bfe93b17dd26bd5e6e4e1c57b88cc2cad152405ef524a3a17dc3a9c50f740a9a83e2bc7c731dbf5b4a7b6fc7480c0881bf7ea174f86f593deb4f544f9a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,4 @@
1
+ ### 0.1.0 / 2023-07-01
1
2
  ### 0.0.1 / 2023-07-01
2
3
 
3
4
  * Everything is new. First release
data/Manifest.txt CHANGED
@@ -3,3 +3,8 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/ordlite.rb
6
+ lib/ordlite/models/blob.rb
7
+ lib/ordlite/models/forward.rb
8
+ lib/ordlite/models/inscribe.rb
9
+ lib/ordlite/schema.rb
10
+ lib/ordlite/version.rb
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'hoe'
2
- ## require './lib/ordlite/version.rb'
2
+ require './lib/ordlite/version.rb'
3
3
 
4
4
  Hoe.spec 'ordlite' do
5
5
 
6
- self.version = '0.0.1' ##Pixelart::Module::Ordgen::VERSION
6
+ self.version = Ordlite::VERSION
7
7
 
8
8
 
9
9
  self.summary = "ordlite - ordinals inscription (on bitcoin & co) database let's you query via sql and more"
@@ -20,6 +20,11 @@ Hoe.spec 'ordlite' do
20
20
 
21
21
  self.extra_deps = [
22
22
  ['activerecord'],
23
+ ['activerecord-utils'],
24
+ ['logutils'],
25
+ ['logutils-activerecord'],
26
+ ['props'],
27
+ ['props-activerecord'],
23
28
  ['sqlite3'],
24
29
  ]
25
30
 
@@ -0,0 +1,11 @@
1
+
2
+ module OrdDb
3
+ module Model
4
+
5
+ class Blob < ActiveRecord::Base
6
+ belongs_to :inscribe, foreign_key: 'id'
7
+ end # class Blob
8
+
9
+ end # module Model
10
+ end # module OrdDb
11
+
@@ -0,0 +1,23 @@
1
+
2
+ ### forward references
3
+ ## require first to resolve circular references
4
+
5
+ module OrdDb
6
+ module Model
7
+
8
+ #############
9
+ # ConfDb
10
+ Prop = ConfDb::Model::Prop
11
+
12
+
13
+ class Inscribe < ActiveRecord::Base ; end
14
+ class Blob < ActiveRecord::Base ; end
15
+
16
+ end
17
+
18
+ # note: convenience alias for Model
19
+ # lets you use include OrdDb::Models
20
+ Models = Model
21
+ end # module # OrdDb
22
+
23
+
@@ -0,0 +1,11 @@
1
+
2
+ module OrdDb
3
+ module Model
4
+
5
+ class Inscribe < ActiveRecord::Base
6
+ has_one :blob, foreign_key: 'id'
7
+ end # class Inscribe
8
+
9
+ end # module Model
10
+ end # module OrdDb
11
+
@@ -0,0 +1,107 @@
1
+
2
+
3
+ module OrdDb
4
+
5
+ class CreateDb
6
+
7
+ def up
8
+
9
+ ActiveRecord::Schema.define do
10
+
11
+
12
+ =begin
13
+ CREATE TABLE inscribes(
14
+ id varchar NOT NULL PRIMARY KEY,
15
+ num integer NOT NULL,
16
+ content_length integer NOT NULL,
17
+ content_type varchar NOT NULL,
18
+ date datetime(6) NOT NULL,
19
+ sat integer NOT NULL,
20
+ height integer NOT NULL,
21
+ fee integer NOT NULL,
22
+ tx varchar NOT NULL,
23
+ offset integer NOT NULL,
24
+ address varchar NOT NULL,
25
+
26
+ created_at datetime(6) NOT NULL,
27
+ updated_at datetime(6) NOT NULL)
28
+
29
+ CREATE TABLE blobs(
30
+ id varchar NOT NULL PRIMARY KEY,
31
+ content blob NOT NULL
32
+
33
+ created_at datetime(6) NOT NULL,
34
+ updated_at datetime(6) NOT NULL)
35
+ =end
36
+
37
+
38
+
39
+ create_table :inscribes, :id => :string do |t|
40
+ ## "id": "0a3a4dbf6630338bc4df8e36bd081f8f7d2dee9441131cb03a18d43eb4882d5ci0",
41
+ ## note: change to uuid (universally unique id) - why? why not?
42
+ ## id gets used by row_id (internal orm db machinery) and is int
43
+ ## t.string :uuid, null: false, index: { unique: true, name: 'inscribe_uuids' }
44
+
45
+ ## "title": "Inscription 10371414",
46
+ ## note: use num/no. from title only - why? why not?
47
+ t.integer :num, null: false, index: { unique: true, name: 'inscribe_nums' }
48
+
49
+ ## "content length": "85 bytes",
50
+ ## note: extract bytes as integer!!!
51
+ t.integer :content_length, null: false
52
+ ## "content type": "text/plain;charset=utf-8",
53
+ ## note: make sure always lower/down case!!!
54
+ t.string :content_type, null: false
55
+
56
+ ## "timestamp": "2023-06-01 05:00:57 UTC"
57
+ ## or use date_utc ???
58
+ t.datetime :date, null: false
59
+
60
+ ##
61
+ ## "sat": "967502783701719",
62
+ t.integer :sat, null: false
63
+
64
+ ##
65
+ ## "genesis height": "792337",
66
+ ## "genesis fee": "6118",
67
+ ## "genesis transaction": "0a3a4dbf6630338bc4df8e36bd081f8f7d2dee9441131cb03a18d43eb4882d5c",
68
+ ## "offset": "0"
69
+ t.integer :height, null: false
70
+ t.integer :fee, null: false
71
+ t.string :tx, null: false
72
+ t.integer :offset, null: false
73
+
74
+ ###
75
+ ## "address": "bc1p3h4eecuxjj2g72sq38gyva732866u5w29lhxgeqfe6c0sg8xmagsuau63k",
76
+ ## is this minter/inscriber addr???
77
+ t.string :address, null: false
78
+
79
+ ## -- ignore for now - why? why not?
80
+ ## what is output ???
81
+ ## "location": "0a3a4dbf6630338bc4df8e36bd081f8f7d2dee9441131cb03a18d43eb4882d5c:0:0",
82
+ ## "output": "0a3a4dbf6630338bc4df8e36bd081f8f7d2dee9441131cb03a18d43eb4882d5c:0",
83
+ ## "output value": "546",
84
+
85
+ ## timestamp at last
86
+ t.timestamps
87
+ end
88
+
89
+
90
+ create_table :blobs, :id => :string do |t|
91
+ ## "id": "0a3a4dbf6630338bc4df8e36bd081f8f7d2dee9441131cb03a18d43eb4882d5ci0",
92
+ ## note: change to uuid (universally unique id) - why? why not?
93
+ ## id gets used by row_id (internal orm db machinery) and is int
94
+ ## t.string :id, null: false, index: { unique: true, name: 'blob_uuids' }
95
+
96
+ t.binary :content, null: false
97
+
98
+ ## timestamp at last
99
+ t.timestamps
100
+ end
101
+
102
+
103
+ end # block Schema.define
104
+
105
+ end # method up
106
+ end # class CreateDb
107
+ end # module OrdDb
@@ -0,0 +1,22 @@
1
+
2
+ module Ordlite
3
+
4
+ # sync version w/ sport.db n friends - why? why not?
5
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
+ MINOR = 1
7
+ PATCH = 0
8
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
9
+
10
+ def self.version
11
+ VERSION
12
+ end
13
+
14
+ def self.banner
15
+ "ordlite/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in >#{root}<"
16
+ end
17
+
18
+ def self.root
19
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
20
+ end
21
+
22
+ end
data/lib/ordlite.rb CHANGED
@@ -1,3 +1,105 @@
1
+ # core and stlibs
1
2
 
2
- puts "hello, ordlite!"
3
+ require 'pp'
4
+ require 'fileutils'
5
+ require 'uri'
6
+ require 'json'
7
+ require 'yaml'
3
8
 
9
+ require 'logger' # Note: use for ActiveRecord::Base.logger -- remove/replace later w/ LogUtils::Logger ???
10
+
11
+
12
+ # 3rd party gems / libs
13
+ require 'props' # see github.com/rubylibs/props
14
+ require 'logutils' # see github.com/rubylibs/logutils
15
+
16
+
17
+ require 'active_record' ## todo: add sqlite3? etc.
18
+
19
+ ## add more activerecords addons/utils
20
+ # require 'tagutils'
21
+ require 'activerecord/utils'
22
+ require 'props/activerecord' # includes ConfDb (ConfDb::Model::Prop, etc.)
23
+ require 'logutils/activerecord' # includes LogDb (LogDb::Model::Log, etc.)
24
+
25
+
26
+
27
+ # our own code
28
+
29
+ require 'ordlite/version' # always goes first
30
+
31
+ require 'ordlite/models/forward'
32
+
33
+ require 'ordlite/models/inscribe'
34
+ require 'ordlite/models/blob'
35
+
36
+
37
+ require 'ordlite/schema'
38
+
39
+
40
+
41
+ module OrdDb
42
+
43
+ def self.create
44
+ CreateDb.new.up
45
+ ConfDb::Model::Prop.create!( key: 'db.schema.ord.version',
46
+ value: Ordlite::VERSION )
47
+ end
48
+
49
+ def self.create_all
50
+ LogDb.create # add logs table
51
+ ConfDb.create # add props table
52
+ OrdDb.create
53
+ end
54
+
55
+ def self.connect( config={} )
56
+
57
+ if config.empty?
58
+ puts "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
59
+
60
+ ### change default to ./ord.db ?? why? why not?
61
+ db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///ord.db' )
62
+
63
+ if db.scheme == 'postgres'
64
+ config = {
65
+ adapter: 'postgresql',
66
+ host: db.host,
67
+ port: db.port,
68
+ username: db.user,
69
+ password: db.password,
70
+ database: db.path[1..-1],
71
+ encoding: 'utf8'
72
+ }
73
+ else # assume sqlite3
74
+ config = {
75
+ adapter: db.scheme, # sqlite3
76
+ database: db.path[1..-1] # ord.db (NB: cut off leading /, thus 1..-1)
77
+ }
78
+ end
79
+ end
80
+
81
+ puts "Connecting to db using settings: "
82
+ pp config
83
+ ActiveRecord::Base.establish_connection( config )
84
+ # ActiveRecord::Base.logger = Logger.new( STDOUT )
85
+ end
86
+
87
+
88
+ def self.setup_in_memory_db
89
+
90
+ # Database Setup & Config
91
+ ActiveRecord::Base.logger = Logger.new( STDOUT )
92
+ ## ActiveRecord::Base.colorize_logging = false - no longer exists - check new api/config setting?
93
+
94
+ self.connect( adapter: 'sqlite3',
95
+ database: ':memory:' )
96
+
97
+ ## build schema
98
+ OrdDb.create_all
99
+ end # setup_in_memory_db (using SQLite :memory:)
100
+
101
+ end # module OrdDb
102
+
103
+
104
+ # say hello
105
+ puts Ordlite.banner ## if defined?($RUBYCOCOS_DEBUG) && $RUBCOCOS_DEBUG
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordlite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -24,6 +24,76 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord-utils
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: logutils
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: logutils-activerecord
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: props
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: props-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'
27
97
  - !ruby/object:Gem::Dependency
28
98
  name: sqlite3
29
99
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +157,11 @@ files:
87
157
  - README.md
88
158
  - Rakefile
89
159
  - lib/ordlite.rb
160
+ - lib/ordlite/models/blob.rb
161
+ - lib/ordlite/models/forward.rb
162
+ - lib/ordlite/models/inscribe.rb
163
+ - lib/ordlite/schema.rb
164
+ - lib/ordlite/version.rb
90
165
  homepage: https://github.com/ordbase/generative-orc-721
91
166
  licenses:
92
167
  - Public Domain