Module: BSV::Wallet::Postgres

Defined in:
lib/bsv/wallet/postgres.rb,
lib/bsv/wallet/postgres/tag.rb,
lib/bsv/wallet/postgres/block.rb,
lib/bsv/wallet/postgres/input.rb,
lib/bsv/wallet/postgres/label.rb,
lib/bsv/wallet/postgres/store.rb,
lib/bsv/wallet/postgres/action.rb,
lib/bsv/wallet/postgres/basket.rb,
lib/bsv/wallet/postgres/output.rb,
lib/bsv/wallet/postgres/setting.rb,
lib/bsv/wallet/postgres/version.rb,
lib/bsv/wallet/postgres/tx_proof.rb,
lib/bsv/wallet/postgres/broadcast.rb,
lib/bsv/wallet/postgres/spendable.rb,
lib/bsv/wallet/postgres/utxo_pool.rb,
lib/bsv/wallet/postgres/output_tag.rb,
lib/bsv/wallet/postgres/arc_adapter.rb,
lib/bsv/wallet/postgres/certificate.rb,
lib/bsv/wallet/postgres/proof_store.rb,
lib/bsv/wallet/postgres/action_label.rb,
lib/bsv/wallet/postgres/display_txid.rb,
lib/bsv/wallet/postgres/output_basket.rb,
lib/bsv/wallet/postgres/output_detail.rb,
lib/bsv/wallet/postgres/broadcast_queue.rb,
lib/bsv/wallet/postgres/certificate_field.rb,
lib/bsv/wallet/postgres/broadcast_callback.rb

Overview

PostgreSQL adapter for bsv-wallet.

Call Postgres.connect before using any models. Loads the pg_enum and pg_array Sequel extensions and sets Sequel::Model.db for all models in this namespace.

Defined Under Namespace

Modules: DisplayTxid Classes: Action, ActionLabel, ArcAdapter, Basket, Block, Broadcast, BroadcastCallback, BroadcastQueue, Certificate, CertificateField, Input, Label, Output, OutputBasket, OutputDetail, OutputTag, ProofStore, Setting, Spendable, Store, Tag, TxProof, UTXOPool

Constant Summary collapse

VERSION =
'0.100.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dbSequel::Database? (readonly)

Returns the connected database.

Returns:

  • (Sequel::Database, nil)

    the connected database



45
46
47
# File 'lib/bsv/wallet/postgres.rb', line 45

def db
  @db
end

Class Method Details

.connect(url_or_db) ⇒ Sequel::Database

Establish a database connection for all models.

Parameters:

  • url_or_db (String, Sequel::Database)

    connection URL or existing database

Returns:

  • (Sequel::Database)


51
52
53
54
55
56
57
58
# File 'lib/bsv/wallet/postgres.rb', line 51

def connect(url_or_db)
  @db = url_or_db.is_a?(Sequel::Database) ? url_or_db : Sequel.connect(url_or_db)
  @db.extension :pg_enum
  @db.extension :pg_array
  @db.extension :pg_json
  Sequel::Model.db = @db
  @db
end

.disconnectObject

Disconnect and clear the database reference.



61
62
63
64
# File 'lib/bsv/wallet/postgres.rb', line 61

def disconnect
  @db&.disconnect
  @db = nil
end

.migrate!(target: nil) ⇒ Object

Run pending migrations against the connected database.

Parameters:

  • target (Integer, nil) (defaults to: nil)

    optional target migration version



69
70
71
72
73
# File 'lib/bsv/wallet/postgres.rb', line 69

def migrate!(target: nil)
  Sequel.extension :migration
  migrations_path = File.expand_path('../../db/migrations', __dir__)
  Sequel::Migrator.run(@db, migrations_path, target: target)
end