Module: Ladybug

Extended by:
Loggability
Defined in:
lib/ladybug.rb,
ext/ladybug_ext/ladybug_ext.c,
ext/ladybug_ext/ladybug_ext.c

Overview

The top level namespace for Ladybug classes.

Defined Under Namespace

Classes: Config, Connection, ConnectionError, Database, DatabaseError, Error, FinishedError, Node, PreparedStatement, QueryError, QuerySummary, RecursiveRel, Rel, Result

Constant Summary collapse

VERSION =

Library version

'0.2.0'

Class Method Summary collapse

Class Method Details

.database(path = '', **config) ⇒ Object

Create and return a Ladybug::Database. If path is nil, an empty string, or the Symbol :memory, creates an in-memory database. Valid options are:

:buffer_pool_size : Max size of the buffer pool in bytes.

:max_num_threads : The maximum number of threads to use during query execution.

:enable_compression : Whether or not to compress data on-disk for supported types

:read_only : If true, open the database in read-only mode. No write transaction is allowed on the Database object. If false, open the database read-write.

:max_db_size : The maximum size of the database in bytes.

:auto_checkpoint : If true, the database will automatically checkpoint when the size of the WAL file exceeds the checkpoint threshold.

:checkpoint_threshold : The threshold of the WAL file size in bytes. When the size of the WAL file exceeds this threshold, the database will checkpoint if auto_checkpoint is true.



50
51
52
53
54
# File 'lib/ladybug.rb', line 50

def self::database( path='', **config )
	path = '' if path.nil? || path == :memory
	self.log.info "Opening database %p" % [ path ]
	return Ladybug::Database.new( path.to_s, **config )
end

.is_database?(pathname) ⇒ Boolean

Returns true if the specified pathname appears to be a valid Ladybug database for the current version of the storage format.

Returns:

  • (Boolean)


59
60
61
62
63
64
# File 'lib/ladybug.rb', line 59

def self::is_database?( pathname )
	pathname = Pathname( pathname )
	return false unless pathname.file?
	magic = pathname.read( 5 )
	return magic[0, 4] == 'LBUG' && magic[4, 1].ord == Ladybug.storage_version
end

.ladybug_versionString

Return the version of the underlying LadybugDB library.

Returns:

  • (String)


94
95
96
97
98
99
100
# File 'ext/ladybug_ext/ladybug_ext.c', line 94

static VALUE
rlbug_s_ladybug_version( VALUE _ )
{
	const char *version = lbug_get_version();

	return rb_str_new2( version );
}

.storage_versionInteger

Return the storage version used by the underlying library.

Returns:

  • (Integer)


110
111
112
113
114
115
116
# File 'ext/ladybug_ext/ladybug_ext.c', line 110

static VALUE
rlbug_s_storage_version( VALUE _ )
{
	const unsigned long long version = lbug_get_storage_version();

	return ULONG2NUM( version );
}

.timestamp_from_timestamp_ms(milliseconds) ⇒ Object

Return a Time object from the given milliseconds epoch time.



69
70
71
72
# File 'lib/ladybug.rb', line 69

def self::timestamp_from_timestamp_ms( milliseconds )
	seconds, subsec = milliseconds.divmod( 1_000 )
	return Time.at( seconds, subsec, :millisecond )
end

.timestamp_from_timestamp_ns(nanoseconds) ⇒ Object

Return a Time object from the given nanoseconds epoch time.



84
85
86
87
# File 'lib/ladybug.rb', line 84

def self::timestamp_from_timestamp_ns( nanoseconds )
	seconds, subsec = nanoseconds.divmod( 1_000_000_000 )
	return Time.at( seconds, subsec, :nanosecond )
end

.timestamp_from_timestamp_us(microseconds, zone = nil) ⇒ Object

Return a Time object from the given microseconds epoch time and optional timezone offset in seconds via the zone argument.



77
78
79
80
# File 'lib/ladybug.rb', line 77

def self::timestamp_from_timestamp_us( microseconds, zone=nil )
	seconds, subsec = microseconds.divmod( 1_000_000 )
	return Time.at( seconds, subsec, :microsecond, in: zone )
end