gloo-sqlite 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/gloo-sqlite.rb +20 -0
- data/lib/sqlite.rb +170 -0
- metadata +66 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 358f0d80e1879440453c4c01311f055fefb9a87e92125ccc42122dcb6905c62c
|
|
4
|
+
data.tar.gz: 01ff74b4fad261755fb71a12c8f2666b890399404a4545cbc63f2990003701ba
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 94194965ec358dee75e36af958f95b8429e92439159e9753762452d6097129a17589c263befcefdf45a12f8b3cdcc972711bf17c079997e9860b9e0adc4d6fe7
|
|
7
|
+
data.tar.gz: 79f858e490a8441d4d9e4c7b062f32191cad2f352c5e698017f90003138b68881647f16c830cfc2884510fe18dd783b93cf1c1fcc55f8e65765fdebdaa35742f
|
data/lib/gloo-sqlite.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Shim to allow `require 'gloo-sqlite'`
|
|
3
|
+
#
|
|
4
|
+
# This file is loaded when someone does `require 'gloo-sqlite'`
|
|
5
|
+
#
|
|
6
|
+
require 'sqlite3'
|
|
7
|
+
|
|
8
|
+
#
|
|
9
|
+
# Registers the extension.
|
|
10
|
+
#
|
|
11
|
+
class SqliteInit < Gloo::Plugin::Base
|
|
12
|
+
|
|
13
|
+
#
|
|
14
|
+
# Register verbs and objects.
|
|
15
|
+
#
|
|
16
|
+
def register( callback )
|
|
17
|
+
callback.register_obj( Sqlite )
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
data/lib/sqlite.rb
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# A Sqlite3 database connection.
|
|
5
|
+
#
|
|
6
|
+
# https://www.rubydoc.info/gems/sqlite3/1.3.11
|
|
7
|
+
# https://www.devdungeon.com/content/ruby-sqlite-tutorial
|
|
8
|
+
#
|
|
9
|
+
# db.results_as_hash = true
|
|
10
|
+
# Set results to return as Hash object.
|
|
11
|
+
# This is slower but offers a huge convenience.
|
|
12
|
+
# Consider turning it off for high performance situations.
|
|
13
|
+
# Each row will have the column name as the hash key.
|
|
14
|
+
#
|
|
15
|
+
# # Alternatively, to only get one row and discard the rest,
|
|
16
|
+
# replace `db.query()` with `db.get_first_value()`.
|
|
17
|
+
#
|
|
18
|
+
require 'sqlite3'
|
|
19
|
+
|
|
20
|
+
class Sqlite < Gloo::Core::Obj
|
|
21
|
+
|
|
22
|
+
KEYWORD = 'sqlite'.freeze
|
|
23
|
+
KEYWORD_SHORT = 'sqlite'.freeze
|
|
24
|
+
|
|
25
|
+
DB = 'database'.freeze
|
|
26
|
+
DEFAULT_DB = 'test.db'.freeze
|
|
27
|
+
|
|
28
|
+
DB_REQUIRED_ERR = 'The database name is required!'.freeze
|
|
29
|
+
DB_NOT_FOUND_ERR = 'The database file was not found!'.freeze
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# The name of the object type.
|
|
33
|
+
#
|
|
34
|
+
def self.typename
|
|
35
|
+
return KEYWORD
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#
|
|
39
|
+
# The short name of the object type.
|
|
40
|
+
#
|
|
41
|
+
def self.short_typename
|
|
42
|
+
return KEYWORD_SHORT
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# ---------------------------------------------------------------------
|
|
46
|
+
# Children
|
|
47
|
+
# ---------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
# Does this object have children to add when an object
|
|
51
|
+
# is created in interactive mode?
|
|
52
|
+
# This does not apply during obj load, etc.
|
|
53
|
+
#
|
|
54
|
+
def add_children_on_create?
|
|
55
|
+
return true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#
|
|
59
|
+
# Add children to this object.
|
|
60
|
+
# This is used by containers to add children needed
|
|
61
|
+
# for default configurations.
|
|
62
|
+
#
|
|
63
|
+
def add_default_children
|
|
64
|
+
fac = @engine.factory
|
|
65
|
+
fac.create_string DB, DEFAULT_DB, self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# ---------------------------------------------------------------------
|
|
69
|
+
# Messages
|
|
70
|
+
# ---------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
#
|
|
73
|
+
# Get a list of message names that this object receives.
|
|
74
|
+
#
|
|
75
|
+
def self.messages
|
|
76
|
+
return super + [ 'verify' ]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# Verify access to the Sqlite database specified.
|
|
81
|
+
#
|
|
82
|
+
def msg_verify
|
|
83
|
+
name = db_value
|
|
84
|
+
if name.empty?
|
|
85
|
+
@engine.err DB_REQUIRED_ERR
|
|
86
|
+
@engine.heap.it.set_to false
|
|
87
|
+
return
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
unless File.exist? name
|
|
91
|
+
@engine.err DB_NOT_FOUND_ERR
|
|
92
|
+
@engine.heap.it.set_to false
|
|
93
|
+
return
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
return unless connects?
|
|
97
|
+
|
|
98
|
+
@engine.heap.it.set_to true
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# ---------------------------------------------------------------------
|
|
102
|
+
# DB functions (all database connections)
|
|
103
|
+
# ---------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
#
|
|
106
|
+
# Open a connection and execute the SQL statement.
|
|
107
|
+
# Return the resulting data.
|
|
108
|
+
#
|
|
109
|
+
def query( sql, params = nil )
|
|
110
|
+
name = db_value
|
|
111
|
+
unless name
|
|
112
|
+
@engine.err DB_REQUIRED_ERR
|
|
113
|
+
return
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
db = SQLite3::Database.open name
|
|
117
|
+
# db.results_as_hash = true
|
|
118
|
+
results = db.query( sql, params )
|
|
119
|
+
|
|
120
|
+
return results
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#
|
|
124
|
+
# Based on the result set, build a QueryResult object.
|
|
125
|
+
#
|
|
126
|
+
def get_query_result( result )
|
|
127
|
+
rows = []
|
|
128
|
+
while ( row = result.next ) do
|
|
129
|
+
rows << row
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
return QueryResult.new( result.columns, rows )
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# ---------------------------------------------------------------------
|
|
137
|
+
# Private functions
|
|
138
|
+
# ---------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
private
|
|
141
|
+
|
|
142
|
+
#
|
|
143
|
+
# Get the Database file from the child object.
|
|
144
|
+
# Returns nil if there is none.
|
|
145
|
+
#
|
|
146
|
+
def db_value
|
|
147
|
+
o = find_child DB
|
|
148
|
+
return nil unless o
|
|
149
|
+
|
|
150
|
+
return o.value
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
#
|
|
154
|
+
# Try the connection and make sure it works.
|
|
155
|
+
# Returns true if we can connect and do a query.
|
|
156
|
+
#
|
|
157
|
+
def connects?
|
|
158
|
+
begin
|
|
159
|
+
db = SQLite3::Database.open db_value
|
|
160
|
+
sql = "SELECT COUNT(name) FROM sqlite_master WHERE type='table'"
|
|
161
|
+
db.get_first_value sql
|
|
162
|
+
rescue => e
|
|
163
|
+
@engine.log_exception e
|
|
164
|
+
@engine.heap.it.set_to false
|
|
165
|
+
return false
|
|
166
|
+
end
|
|
167
|
+
return true
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gloo-sqlite
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.0'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Eric Crane
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-01-24 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: sqlite3
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.4'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.4.2
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.4'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.4.2
|
|
33
|
+
description: Adds SQLite support to Gloo.
|
|
34
|
+
email:
|
|
35
|
+
- eric.crane@mac.com
|
|
36
|
+
executables: []
|
|
37
|
+
extensions: []
|
|
38
|
+
extra_rdoc_files: []
|
|
39
|
+
files:
|
|
40
|
+
- lib/gloo-sqlite.rb
|
|
41
|
+
- lib/sqlite.rb
|
|
42
|
+
homepage: https://gloo.ecrane.us/
|
|
43
|
+
licenses:
|
|
44
|
+
- MIT
|
|
45
|
+
metadata:
|
|
46
|
+
gloo.type: core-library
|
|
47
|
+
post_install_message:
|
|
48
|
+
rdoc_options: []
|
|
49
|
+
require_paths:
|
|
50
|
+
- lib
|
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
requirements: []
|
|
62
|
+
rubygems_version: 3.5.16
|
|
63
|
+
signing_key:
|
|
64
|
+
specification_version: 4
|
|
65
|
+
summary: Gloo core library. SQLite support.
|
|
66
|
+
test_files: []
|