Documentation
ΒΆ
Overview ΒΆ
Package dgraph provides a Dgraph-based implementation of the database interface. This is a simplified implementation for testing - full dgraph integration to be completed later.
Index ΒΆ
- Constants
- func NewLogger(logLevel int, label string) (l *logger)
- type D
- func (d *D) AddNIP43Member(pubkey []byte, inviteCode string) error
- func (d *D) CacheEvents(f *filter.F, events event.S)
- func (d *D) CacheMarshaledJSON(f *filter.F, marshaledJSON [][]byte)
- func (d *D) CheckForDeleted(ev *event.E, admins [][]byte) (err error)
- func (d *D) Close() (err error)
- func (d *D) CountEvents(c context.Context, f *filter.F) (count int, approximate bool, err error)
- func (d *D) DeleteEvent(c context.Context, eid []byte) error
- func (d *D) DeleteEventBySerial(c context.Context, ser *types.Uint40, ev *event.E) error
- func (d *D) DeleteExpired()
- func (d *D) DeleteInviteCode(code string) error
- func (d *D) DeleteMarker(key string) error
- func (d *D) EventIdsBySerial(start uint64, count int) (evs []uint64, err error)
- func (d *D) Export(c context.Context, w io.Writer, pubkeys ...[]byte)
- func (d *D) ExtendBlossomSubscription(pubkey []byte, tier string, storageMB int64, daysExtended int) error
- func (d *D) ExtendSubscription(pubkey []byte, days int) error
- func (d *D) FetchEventBySerial(ser *types.Uint40) (ev *event.E, err error)
- func (d *D) FetchEventsBySerials(serials []*types.Uint40) (events map[uint64]*event.E, err error)
- func (d *D) GetAllNIP43Members() ([][]byte, error)
- func (d *D) GetBlossomStorageQuota(pubkey []byte) (quotaMB int64, err error)
- func (d *D) GetCachedEvents(f *filter.F) (event.S, bool)
- func (d *D) GetCachedJSON(f *filter.F) ([][]byte, bool)
- func (d *D) GetFullIdPubkeyBySerial(ser *types.Uint40) (fidpk *store.IdPkTs, err error)
- func (d *D) GetFullIdPubkeyBySerials(sers []*types.Uint40) (fidpks []*store.IdPkTs, err error)
- func (d *D) GetMarker(key string) (value []byte, err error)
- func (d *D) GetNIP43Membership(pubkey []byte) (*database.NIP43Membership, error)
- func (d *D) GetOrCreateRelayIdentitySecret() (skb []byte, err error)
- func (d *D) GetPaymentHistory(pubkey []byte) ([]database.Payment, error)
- func (d *D) GetRelayIdentitySecret() (skb []byte, err error)
- func (d *D) GetSerialById(id []byte) (ser *types.Uint40, err error)
- func (d *D) GetSerialsByIds(ids *tag.T) (serials map[string]*types.Uint40, err error)
- func (d *D) GetSerialsByIdsWithFilter(ids *tag.T, fn func(ev *event.E, ser *types.Uint40) bool) (serials map[string]*types.Uint40, err error)
- func (d *D) GetSerialsByRange(idx database.Range) (serials types.Uint40s, err error)
- func (d *D) GetSerialsFromFilter(f *filter.F) (serials types.Uint40s, err error)
- func (d *D) GetSubscription(pubkey []byte) (*database.Subscription, error)
- func (d *D) HasMarker(key string) bool
- func (d *D) Import(rr io.Reader)
- func (d *D) ImportEventsFromReader(ctx context.Context, rr io.Reader) error
- func (d *D) ImportEventsFromStrings(ctx context.Context, eventJSONs []string, policyManager interface{ ... }) error
- func (d *D) Init(path string) (err error)
- func (d *D) InvalidateQueryCache()
- func (d *D) IsFirstTimeUser(pubkey []byte) (bool, error)
- func (d *D) IsNIP43Member(pubkey []byte) (isMember bool, err error)
- func (d *D) IsSubscriptionActive(pubkey []byte) (bool, error)
- func (d *D) Mutate(ctx context.Context, mutation *api.Mutation) (*api.Response, error)
- func (d *D) Path() string
- func (d *D) ProcessDelete(ev *event.E, admins [][]byte) (err error)
- func (d *D) PublishNIP43MembershipEvent(kind int, pubkey []byte) error
- func (d *D) Query(ctx context.Context, query string) (*api.Response, error)
- func (d *D) QueryAllVersions(c context.Context, f *filter.F) (evs event.S, err error)
- func (d *D) QueryDeleteEventsByTargetId(c context.Context, targetEventId []byte) (evs event.S, err error)
- func (d *D) QueryEvents(c context.Context, f *filter.F) (evs event.S, err error)
- func (d *D) QueryEventsWithOptions(c context.Context, f *filter.F, includeDeleteEvents bool, showAllVersions bool) (evs event.S, err error)
- func (d *D) QueryForIds(c context.Context, f *filter.F) (idPkTs []*store.IdPkTs, err error)
- func (d *D) QueryForSerials(c context.Context, f *filter.F) (serials types.Uint40s, err error)
- func (d *D) Ready() <-chan struct{}
- func (d *D) RecordPayment(pubkey []byte, amount int64, invoice, preimage string) error
- func (d *D) RemoveNIP43Member(pubkey []byte) error
- func (d *D) RunMigrations()
- func (d *D) SaveEvent(c context.Context, ev *event.E) (exists bool, err error)
- func (d *D) SetLogLevel(level string)
- func (d *D) SetMarker(key string, value []byte) error
- func (d *D) SetRelayIdentitySecret(skb []byte) error
- func (d *D) StoreInviteCode(code string, expiresAt time.Time) error
- func (d *D) Sync() (err error)
- func (d *D) ValidateInviteCode(code string) (valid bool, err error)
- func (d *D) Wipe() (err error)
- func (d *D) WouldReplaceEvent(ev *event.E) (bool, types.Uint40s, error)
Constants ΒΆ
const NostrSchema = `` /* 1159-byte string literal not displayed */
NostrSchema defines the Dgraph schema for Nostr events
Variables ΒΆ
This section is empty.
Functions ΒΆ
Types ΒΆ
type D ΒΆ
type D struct {
Logger *logger
// contains filtered or unexported fields
}
D implements the database.Database interface using Dgraph as the storage backend
func New ΒΆ
func New( ctx context.Context, cancel context.CancelFunc, dataDir, logLevel string, ) ( d *D, err error, )
New creates a new Dgraph-based database instance with default configuration. This is provided for backward compatibility with existing callers (tests, etc.). For full configuration control, use NewWithConfig instead.
func NewWithConfig ΒΆ added in v0.31.8
func NewWithConfig( ctx context.Context, cancel context.CancelFunc, cfg *database.DatabaseConfig, ) ( d *D, err error, )
NewWithConfig creates a new Dgraph-based database instance with full configuration. Configuration is passed from the centralized app config via DatabaseConfig.
func (*D) AddNIP43Member ΒΆ
AddNIP43Member adds a member using an invite code
func (*D) CheckForDeleted ΒΆ
CheckForDeleted checks if an event has been deleted
func (*D) CountEvents ΒΆ
CountEvents counts events matching a filter
func (*D) DeleteEvent ΒΆ
DeleteEvent deletes an event by its ID
func (*D) DeleteEventBySerial ΒΆ
DeleteEventBySerial deletes an event by its serial number
func (*D) DeleteExpired ΒΆ
func (d *D) DeleteExpired()
DeleteExpired removes events that have passed their expiration time (NIP-40)
func (*D) DeleteInviteCode ΒΆ
DeleteInviteCode removes an invite code
func (*D) DeleteMarker ΒΆ
DeleteMarker removes a metadata marker
func (*D) EventIdsBySerial ΒΆ
EventIdsBySerial retrieves event IDs by serial range
func (*D) Export ΒΆ
Export exports events to a writer (JSONL format)
func (*D) ExtendBlossomSubscription ΒΆ
func (d *D) ExtendBlossomSubscription( pubkey []byte, tier string, storageMB int64, daysExtended int, ) error
ExtendBlossomSubscription extends a Blossom storage subscription
func (*D) ExtendSubscription ΒΆ
ExtendSubscription extends a subscription by the specified number of days
func (*D) FetchEventBySerial ΒΆ
FetchEventBySerial retrieves an event by its serial number
func (*D) FetchEventsBySerials ΒΆ
func (d *D) FetchEventsBySerials(serials []*types.Uint40) ( events map[uint64]*event.E, err error, )
FetchEventsBySerials retrieves multiple events by their serial numbers
func (*D) GetAllNIP43Members ΒΆ
GetAllNIP43Members retrieves all member pubkeys
func (*D) GetBlossomStorageQuota ΒΆ
GetBlossomStorageQuota retrieves the storage quota for a pubkey
func (*D) GetCachedEvents ΒΆ added in v0.29.11
func (*D) GetFullIdPubkeyBySerial ΒΆ
GetFullIdPubkeyBySerial retrieves ID and pubkey for a serial number
func (*D) GetFullIdPubkeyBySerials ΒΆ
GetFullIdPubkeyBySerials retrieves IDs and pubkeys for multiple serials
func (*D) GetMarker ΒΆ
GetMarker retrieves a metadata marker
func (*D) GetNIP43Membership ΒΆ
func (d *D) GetNIP43Membership(pubkey []byte) (*database.NIP43Membership, error)
GetNIP43Membership retrieves membership information
func (*D) GetOrCreateRelayIdentitySecret ΒΆ
GetOrCreateRelayIdentitySecret retrieves or creates the relay identity
func (*D) GetPaymentHistory ΒΆ
GetPaymentHistory retrieves payment history for a pubkey
func (*D) GetRelayIdentitySecret ΒΆ
GetRelayIdentitySecret retrieves the relay's identity secret key
func (*D) GetSerialById ΒΆ
GetSerialById retrieves the serial number for an event ID
func (*D) GetSerialsByIds ΒΆ
GetSerialsByIds retrieves serial numbers for multiple event IDs
func (*D) GetSerialsByIdsWithFilter ΒΆ
func (d *D) GetSerialsByIdsWithFilter( ids *tag.T, fn func(ev *event.E, ser *types.Uint40) bool, ) (serials map[string]*types.Uint40, err error)
GetSerialsByIdsWithFilter retrieves serials with a filter function
func (*D) GetSerialsByRange ΒΆ
GetSerialsByRange retrieves serials within a range
func (*D) GetSerialsFromFilter ΒΆ
GetSerialsFromFilter returns event serials matching a filter
func (*D) GetSubscription ΒΆ
func (d *D) GetSubscription(pubkey []byte) (*database.Subscription, error)
GetSubscription retrieves subscription information for a pubkey
func (*D) Import ΒΆ
Import imports events from a reader (JSONL format)
func (*D) ImportEventsFromReader ΒΆ
ImportEventsFromReader imports events from a reader
func (*D) ImportEventsFromStrings ΒΆ
func (d *D) ImportEventsFromStrings( ctx context.Context, eventJSONs []string, policyManager interface { CheckPolicy(action string, ev *event.E, pubkey []byte, remote string) (bool, error) }, ) error
ImportEventsFromStrings imports events from JSON strings
func (*D) Init ΒΆ
Init initializes the database with a given path (no-op, path set in New)
func (*D) IsFirstTimeUser ΒΆ
IsFirstTimeUser checks if a pubkey is a first-time user
func (*D) IsNIP43Member ΒΆ
IsNIP43Member checks if a pubkey is a member
func (*D) IsSubscriptionActive ΒΆ
IsSubscriptionActive checks if a pubkey has an active subscription
func (*D) Mutate ΒΆ
Mutate executes a mutation against dgraph
func (*D) ProcessDelete ΒΆ
ProcessDelete processes a kind 5 deletion event
func (*D) PublishNIP43MembershipEvent ΒΆ
PublishNIP43MembershipEvent publishes a membership event
func (*D) Query ΒΆ
Query executes a DQL query against dgraph
func (*D) QueryAllVersions ΒΆ
QueryAllVersions retrieves all versions of events matching the filter
func (*D) QueryDeleteEventsByTargetId ΒΆ
func (d *D) QueryDeleteEventsByTargetId(c context.Context, targetEventId []byte) ( evs event.S, err error, )
QueryDeleteEventsByTargetId retrieves delete events targeting a specific event ID
func (*D) QueryEvents ΒΆ
QueryEvents retrieves events matching the given filter
func (*D) QueryEventsWithOptions ΒΆ
func (d *D) QueryEventsWithOptions( c context.Context, f *filter.F, includeDeleteEvents bool, showAllVersions bool, ) (evs event.S, err error)
QueryEventsWithOptions retrieves events with specific options
func (*D) QueryForIds ΒΆ
QueryForIds retrieves event IDs matching a filter
func (*D) QueryForSerials ΒΆ
QueryForSerials retrieves event serials matching a filter
func (*D) Ready ΒΆ
func (d *D) Ready() <-chan struct{}
Ready returns a channel that closes when the database is ready to serve requests. This allows callers to wait for database warmup to complete.
func (*D) RecordPayment ΒΆ
RecordPayment records a payment for subscription extension
func (*D) RemoveNIP43Member ΒΆ
RemoveNIP43Member removes a member
func (*D) RunMigrations ΒΆ
func (d *D) RunMigrations()
RunMigrations runs database migrations (no-op for dgraph)
func (*D) SaveEvent ΒΆ
SaveEvent stores a Nostr event in the Dgraph database. It creates event nodes and relationships for authors, tags, and references.
func (*D) SetMarker ΒΆ
SetMarker sets a metadata marker
func (*D) SetRelayIdentitySecret ΒΆ
SetRelayIdentitySecret sets the relay's identity secret key
func (*D) StoreInviteCode ΒΆ
StoreInviteCode stores an invite code with expiration
func (*D) Sync ΒΆ
Sync flushes pending writes (DGraph handles persistence automatically)
func (*D) ValidateInviteCode ΒΆ
ValidateInviteCode checks if an invite code is valid
Source Files
ΒΆ
- delete.go
- dgraph.go
- fetch-event.go
- identity.go
- import-export.go
- logger.go
- markers.go
- nip43.go
- query-events.go
- save-event.go
- schema.go
- serial.go
- subscriptions.go
- utils.go