libsql 0.1.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +60 -0
- data/HISTORY.md +6 -0
- data/LICENSE +31 -0
- data/Manifest.txt +96 -0
- data/README.md +59 -0
- data/Rakefile +28 -0
- data/TODO.md +57 -0
- data/examples/a.rb +9 -0
- data/examples/blob.rb +106 -0
- data/examples/define_aggregate.rb +75 -0
- data/examples/define_function.rb +104 -0
- data/examples/fts5.rb +152 -0
- data/examples/gem-db.rb +94 -0
- data/examples/schema-info.rb +34 -0
- data/ext/libsql/c/extconf.rb +86 -0
- data/ext/libsql/c/gen_constants.rb +353 -0
- data/ext/libsql/c/libsql_blob.c +240 -0
- data/ext/libsql/c/libsql_constants.c +1518 -0
- data/ext/libsql/c/libsql_database.c +1188 -0
- data/ext/libsql/c/libsql_ext.c +383 -0
- data/ext/libsql/c/libsql_ext.h +149 -0
- data/ext/libsql/c/libsql_statement.c +649 -0
- data/ext/libsql/c/notes.txt +134 -0
- data/ext/libsql/c/sqlite3.c +247030 -0
- data/ext/libsql/c/sqlite3.h +13436 -0
- data/lib/libsql/3.0/libsql_ext.so +0 -0
- data/lib/libsql/3.1/libsql_ext.so +0 -0
- data/lib/libsql/3.2/libsql_ext.so +0 -0
- data/lib/libsql/aggregate.rb +73 -0
- data/lib/libsql/blob.rb +186 -0
- data/lib/libsql/boolean.rb +42 -0
- data/lib/libsql/busy_timeout.rb +47 -0
- data/lib/libsql/column.rb +99 -0
- data/lib/libsql/csv_table_importer.rb +75 -0
- data/lib/libsql/database.rb +933 -0
- data/lib/libsql/function.rb +61 -0
- data/lib/libsql/index.rb +43 -0
- data/lib/libsql/memory_database.rb +15 -0
- data/lib/libsql/paths.rb +80 -0
- data/lib/libsql/profile_tap.rb +131 -0
- data/lib/libsql/progress_handler.rb +21 -0
- data/lib/libsql/schema.rb +225 -0
- data/lib/libsql/sqlite3/constants.rb +95 -0
- data/lib/libsql/sqlite3/database/function.rb +48 -0
- data/lib/libsql/sqlite3/database/status.rb +68 -0
- data/lib/libsql/sqlite3/libsql_version.rb +32 -0
- data/lib/libsql/sqlite3/status.rb +60 -0
- data/lib/libsql/sqlite3/version.rb +55 -0
- data/lib/libsql/sqlite3.rb +7 -0
- data/lib/libsql/statement.rb +421 -0
- data/lib/libsql/table.rb +91 -0
- data/lib/libsql/taps/console.rb +27 -0
- data/lib/libsql/taps/io.rb +74 -0
- data/lib/libsql/taps.rb +2 -0
- data/lib/libsql/trace_tap.rb +35 -0
- data/lib/libsql/type_map.rb +63 -0
- data/lib/libsql/type_maps/default_map.rb +166 -0
- data/lib/libsql/type_maps/storage_map.rb +38 -0
- data/lib/libsql/type_maps/text_map.rb +21 -0
- data/lib/libsql/version.rb +8 -0
- data/lib/libsql/view.rb +26 -0
- data/lib/libsql-ruby.rb +1 -0
- data/lib/libsql.rb +51 -0
- data/spec/aggregate_spec.rb +158 -0
- data/spec/blob_spec.rb +78 -0
- data/spec/boolean_spec.rb +24 -0
- data/spec/busy_handler.rb +157 -0
- data/spec/data/iso-3166-country.txt +242 -0
- data/spec/data/iso-3166-schema.sql +22 -0
- data/spec/data/iso-3166-subcountry.txt +3995 -0
- data/spec/data/make-iso-db.sh +12 -0
- data/spec/database_spec.rb +505 -0
- data/spec/default_map_spec.rb +92 -0
- data/spec/function_spec.rb +78 -0
- data/spec/integeration_spec.rb +97 -0
- data/spec/iso_3166_database.rb +58 -0
- data/spec/json_spec.rb +24 -0
- data/spec/libsql_spec.rb +4 -0
- data/spec/paths_spec.rb +28 -0
- data/spec/progress_handler_spec.rb +91 -0
- data/spec/rtree_spec.rb +66 -0
- data/spec/schema_spec.rb +131 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/sqlite3/constants_spec.rb +108 -0
- data/spec/sqlite3/database_status_spec.rb +36 -0
- data/spec/sqlite3/libsql_version_spec.rb +16 -0
- data/spec/sqlite3/status_spec.rb +22 -0
- data/spec/sqlite3/version_spec.rb +28 -0
- data/spec/sqlite3_spec.rb +53 -0
- data/spec/statement_spec.rb +168 -0
- data/spec/storage_map_spec.rb +38 -0
- data/spec/tap_spec.rb +57 -0
- data/spec/text_map_spec.rb +20 -0
- data/spec/type_map_spec.rb +14 -0
- data/spec/version_spec.rb +8 -0
- data/tasks/custom.rake +134 -0
- data/tasks/default.rake +257 -0
- data/tasks/extension.rake +29 -0
- data/tasks/this.rb +208 -0
- metadata +330 -0
data/lib/libsql/table.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
require 'set'
|
6
|
+
module ::Libsql
|
7
|
+
#
|
8
|
+
# a class representing the meta information about an SQLite table
|
9
|
+
#
|
10
|
+
class Table
|
11
|
+
# the schema object the table is associated with
|
12
|
+
attr_accessor :schema
|
13
|
+
|
14
|
+
# the table name
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
# the original sql that was used to create this table
|
18
|
+
attr_reader :sql
|
19
|
+
|
20
|
+
# hash of Index objects holding the meta informationa about the indexes
|
21
|
+
# on this table. The keys of the indexes variable is the index name
|
22
|
+
attr_accessor :indexes
|
23
|
+
|
24
|
+
# a hash of Column objects holding the meta information about the columns
|
25
|
+
# in this table. keys are the column names
|
26
|
+
attr_accessor :columns
|
27
|
+
|
28
|
+
def initialize( name, sql = nil )
|
29
|
+
@name = name
|
30
|
+
@sql = sql
|
31
|
+
@indexes = {}
|
32
|
+
@columns = {}
|
33
|
+
@schema = nil
|
34
|
+
@primary_key = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
# Is the table a temporary table or not
|
38
|
+
def temporary?
|
39
|
+
schema.temporary?
|
40
|
+
end
|
41
|
+
|
42
|
+
# the Columns in original definition order
|
43
|
+
def columns_in_order
|
44
|
+
@columns.values.sort_by { |c| c.order }
|
45
|
+
end
|
46
|
+
|
47
|
+
# the column names in original definition order
|
48
|
+
def column_names
|
49
|
+
columns_in_order.map { |c| c.name }
|
50
|
+
end
|
51
|
+
|
52
|
+
# the columns that make up the primary key
|
53
|
+
def primary_key_columns
|
54
|
+
@columns.values.find_all { |c| c.primary_key? }
|
55
|
+
end
|
56
|
+
|
57
|
+
# the array of colmuns that make up the primary key of the table
|
58
|
+
# since a primary key has an index, we loop over all the indexes for the
|
59
|
+
# table and pick the first one that is unique, and all the columns in the
|
60
|
+
# index have primary_key? as true.
|
61
|
+
#
|
62
|
+
# we do this instead of just looking for the columns where primary key is
|
63
|
+
# true because we want the columns in primary key order
|
64
|
+
def primary_key
|
65
|
+
unless @primary_key
|
66
|
+
pk_column_names = Set.new( primary_key_columns.collect { |c| c.name } )
|
67
|
+
unique_indexes = indexes.values.find_all { |i| i.unique? }
|
68
|
+
|
69
|
+
pk_result = []
|
70
|
+
|
71
|
+
unique_indexes.each do |idx|
|
72
|
+
idx_column_names = Set.new( idx.columns.collect { |c| c.name } )
|
73
|
+
r = idx_column_names ^ pk_column_names
|
74
|
+
if r.size == 0 then
|
75
|
+
pk_result = idx.columns
|
76
|
+
break
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# no joy, see about just using all the columns that say the are primary
|
81
|
+
# keys
|
82
|
+
if pk_result.empty? then
|
83
|
+
pk_result = self.primary_key_columns
|
84
|
+
end
|
85
|
+
@primary_key = pk_result
|
86
|
+
end
|
87
|
+
return @primary_key
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
require 'libsql/taps/io'
|
7
|
+
|
8
|
+
module ::Libsql::Taps
|
9
|
+
#
|
10
|
+
# Class provide an IO tap that can write to $stdout
|
11
|
+
#
|
12
|
+
class Stdout < ::Libsql::Taps::IO
|
13
|
+
def initialize
|
14
|
+
super( $stdout )
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# This class provide an IO tap that can write to $stderr
|
20
|
+
#
|
21
|
+
class Stderr < ::Libsql::Taps::IO
|
22
|
+
def initialize
|
23
|
+
super( $stderr )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
require 'libsql/profile_tap'
|
7
|
+
require 'stringio'
|
8
|
+
|
9
|
+
module ::Libsql
|
10
|
+
module Taps
|
11
|
+
#
|
12
|
+
# An IOTap is an easy way to send all top information to any IO based
|
13
|
+
# object. Both profile and trace tap information can be captured
|
14
|
+
# This means you can send the events to STDOUT with:
|
15
|
+
#
|
16
|
+
# db.profile_tap = db.trace_tap = ::Libsql::Taps::Stdout.new
|
17
|
+
#
|
18
|
+
#
|
19
|
+
class IO
|
20
|
+
|
21
|
+
attr_reader :profile_tap
|
22
|
+
attr_reader :io
|
23
|
+
attr_reader :trace_count
|
24
|
+
|
25
|
+
def initialize( io )
|
26
|
+
@io = io
|
27
|
+
@profile_tap = ProfileTap.new( self, 'output_profile_event' )
|
28
|
+
@trace_count = 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def trace( msg )
|
32
|
+
@trace_count += 1
|
33
|
+
io.puts msg
|
34
|
+
end
|
35
|
+
|
36
|
+
# need a profile method, it routes through the profile tap which calls back
|
37
|
+
# to output_profile_event
|
38
|
+
def profile( msg, time )
|
39
|
+
@profile_tap.profile(msg, time)
|
40
|
+
end
|
41
|
+
|
42
|
+
def output_profile_event( msg, time )
|
43
|
+
io.puts "#{time} : #{msg}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def dump_profile
|
47
|
+
samplers.each_pair do |k,v|
|
48
|
+
io.puts v.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def samplers
|
53
|
+
profile_tap.samplers
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# This class provides an IO tap that writes to a StringIO. The result is
|
59
|
+
# available via .to_s or .string.
|
60
|
+
#
|
61
|
+
class StringIO < ::Libsql::Taps::IO
|
62
|
+
def initialize
|
63
|
+
@stringio = ::StringIO.new
|
64
|
+
super( @stringio )
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_s
|
68
|
+
@stringio.string
|
69
|
+
end
|
70
|
+
alias :string :to_s
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
data/lib/libsql/taps.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
module ::Libsql
|
7
|
+
#
|
8
|
+
# A TraceTap receives tracing information from SQLite3. It receives the SQL
|
9
|
+
# statement being executed as a +msg+ just before the statement first begins
|
10
|
+
# executing.
|
11
|
+
#
|
12
|
+
# A TraceTap is a wrapper around another object and a method. The Tap object
|
13
|
+
# will receive the call to +trace+ and redirect that call to another object
|
14
|
+
# and method.
|
15
|
+
#
|
16
|
+
class TraceTap
|
17
|
+
|
18
|
+
attr_reader :delegate_obj
|
19
|
+
attr_reader :delegate_method
|
20
|
+
|
21
|
+
def initialize( wrapped_obj, send_to = 'trace' )
|
22
|
+
unless wrapped_obj.respond_to?( send_to )
|
23
|
+
raise ::Libsql::Error, "#{wrapped_obj.class.name} does not respond to #{send_to.to_s} "
|
24
|
+
end
|
25
|
+
|
26
|
+
@delegate_obj = wrapped_obj
|
27
|
+
@delegate_method = send_to
|
28
|
+
end
|
29
|
+
|
30
|
+
def trace( msg )
|
31
|
+
delegate_obj.send( delegate_method, msg )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
module Libsql
|
6
|
+
##
|
7
|
+
# TypeMap defines the protocol used between Ruby and SQLite for mapping
|
8
|
+
# binding types, used in prepared statements; and result types, used in
|
9
|
+
# returning objects from a query.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
class TypeMap
|
13
|
+
##
|
14
|
+
# :call-seq:
|
15
|
+
# map.bind_type_of( obj ) -> DataType constant
|
16
|
+
#
|
17
|
+
# bind_type_of is called during the Statement#bind process to convert the
|
18
|
+
# bind parameter to the appropriate SQLite types. This method MUST return
|
19
|
+
# one of the valid constants in the namespace
|
20
|
+
# Libsql::SQLite::Constants::DataType
|
21
|
+
#
|
22
|
+
def bind_type_of( obj )
|
23
|
+
raise NotImplementedError, "bind_type_of has not been implemented"
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# :call-seq:
|
28
|
+
# map.result_value_of( declared_type, value ) -> String
|
29
|
+
#
|
30
|
+
# result_value_of is called during the result processing of column values
|
31
|
+
# to convert an SQLite database value into the appropriate Ruby class.
|
32
|
+
#
|
33
|
+
# +declared_type+ is the string from the original CREATE TABLE statment
|
34
|
+
# from which the column value originates. It may also be nil if the origin
|
35
|
+
# column cannot be determined.
|
36
|
+
#
|
37
|
+
# +value+ is the SQLite value from the column as either a Ruby String,
|
38
|
+
# Integer, Float or Libsql::Blob.
|
39
|
+
#
|
40
|
+
# result_value should return the value that is to be put into the result set
|
41
|
+
# for the query. It may do nothing, or it may do massive amounts of
|
42
|
+
# conversion.
|
43
|
+
def result_value_of( delcared_type, value )
|
44
|
+
raise NotImplementedError, "result_value_of has not been implemented"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# The TypeMaps module holds all typemaps that ship with libsql. They
|
50
|
+
# currently are:
|
51
|
+
#
|
52
|
+
# DefaultMap:: does a 'best-guess' mapping to convert as many types as
|
53
|
+
# possible to known ruby classes from known SQL types.
|
54
|
+
# StorageMap:: converts to a limited set of classes directly based
|
55
|
+
# upon the SQLite storage types
|
56
|
+
# TextMap:: Everything is Text ... everything everything everything
|
57
|
+
#
|
58
|
+
module TypeMaps
|
59
|
+
end
|
60
|
+
end
|
61
|
+
require 'libsql/type_maps/default_map'
|
62
|
+
require 'libsql/type_maps/storage_map'
|
63
|
+
require 'libsql/type_maps/text_map'
|
@@ -0,0 +1,166 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
require 'time'
|
7
|
+
require 'date'
|
8
|
+
|
9
|
+
module ::Libsql::TypeMaps
|
10
|
+
##
|
11
|
+
# An ::Libsql::TypeMap that does its best to convert between Ruby classes
|
12
|
+
# and known SQL data types.
|
13
|
+
#
|
14
|
+
# Upon instantiation, DefaultMap generates a conversion map to try to figure
|
15
|
+
# out the best way to convert between populate SQL 'types' and ruby classes
|
16
|
+
#
|
17
|
+
class DefaultMap
|
18
|
+
class << self
|
19
|
+
def methods_handling_sql_types # :nodoc:
|
20
|
+
@methods_handling_sql_types ||= {
|
21
|
+
'date' => %w[ date ],
|
22
|
+
'datetime' => %w[ datetime ],
|
23
|
+
'time' => %w[ timestamp time ],
|
24
|
+
'float' => %w[ double float real numeric decimal ],
|
25
|
+
'integer' => %w[ integer tinyint smallint int int2 int4 int8 bigint serial bigserial ],
|
26
|
+
'string' => %w[ text char string varchar character json ],
|
27
|
+
'boolean' => %w[ bool boolean ],
|
28
|
+
'blob' => %w[ binary blob ],
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# say what method to call to convert an sql type to a ruby type
|
33
|
+
#
|
34
|
+
def sql_to_method( sql_type ) # :nodoc:
|
35
|
+
unless defined? @sql_to_method
|
36
|
+
@sql_to_method = {}
|
37
|
+
methods_handling_sql_types.each_pair do |method, sql_types|
|
38
|
+
sql_types.each { |t| @sql_to_method[t] = method }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return_method = @sql_to_method[sql_type]
|
42
|
+
|
43
|
+
# the straight lookup didn't work, try iterating through the types and
|
44
|
+
# see what is found
|
45
|
+
unless return_method
|
46
|
+
@sql_to_method.each_pair do |sql, method|
|
47
|
+
if sql_type.index(sql) then
|
48
|
+
return_method = method
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return return_method
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def initialize
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# A straight logical mapping (for me at least) of basic Ruby classes to SQLite types, if
|
62
|
+
# nothing can be found then default to TEXT.
|
63
|
+
#
|
64
|
+
def bind_type_of( obj )
|
65
|
+
case obj
|
66
|
+
when Float
|
67
|
+
::Libsql::SQLite3::Constants::DataType::FLOAT
|
68
|
+
when Integer
|
69
|
+
::Libsql::SQLite3::Constants::DataType::INTEGER
|
70
|
+
when NilClass
|
71
|
+
::Libsql::SQLite3::Constants::DataType::NULL
|
72
|
+
when ::Libsql::Blob
|
73
|
+
::Libsql::SQLite3::Constants::DataType::BLOB
|
74
|
+
else
|
75
|
+
::Libsql::SQLite3::Constants::DataType::TEXT
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Map the incoming value to an outgoing value. For some incoming values,
|
81
|
+
# there will be no change, but for some (i.e. Dates and Times) there is some
|
82
|
+
# conversion
|
83
|
+
#
|
84
|
+
def result_value_of( declared_type, value )
|
85
|
+
case value
|
86
|
+
when Numeric
|
87
|
+
return value
|
88
|
+
when NilClass
|
89
|
+
return value
|
90
|
+
when ::Libsql::Blob
|
91
|
+
return value
|
92
|
+
when String
|
93
|
+
if declared_type then
|
94
|
+
conversion_method = DefaultMap.sql_to_method( declared_type.downcase )
|
95
|
+
if conversion_method then
|
96
|
+
return send(conversion_method, value)
|
97
|
+
else
|
98
|
+
raise ::Libsql::Error, "Unable to convert SQL type of #{declared_type} to a Ruby class"
|
99
|
+
end
|
100
|
+
else
|
101
|
+
# unable to do any other conversion, just return what we have.
|
102
|
+
return value
|
103
|
+
end
|
104
|
+
else
|
105
|
+
raise ::Libsql::Error, "Unable to convert a class #{value.class.name} with value #{value.inspect}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# convert a string to a date
|
111
|
+
#
|
112
|
+
def date( str )
|
113
|
+
Date.parse( str )
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# convert a string to a datetime, if no timzone is found in the parsed
|
118
|
+
# string, set it to the local offset.
|
119
|
+
#
|
120
|
+
def datetime( str )
|
121
|
+
DateTime.parse( str )
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# convert a string to a Time
|
126
|
+
#
|
127
|
+
def time( str )
|
128
|
+
Time.parse( str )
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# convert a string to a Float
|
133
|
+
#
|
134
|
+
def float( str )
|
135
|
+
Float( str )
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# convert an string to an Integer
|
140
|
+
#
|
141
|
+
def integer( str )
|
142
|
+
Float( str ).to_i
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# convert a string to a String, yes redundant I know.
|
147
|
+
#
|
148
|
+
def string( str )
|
149
|
+
str
|
150
|
+
end
|
151
|
+
|
152
|
+
##
|
153
|
+
# convert a string to true of false
|
154
|
+
#
|
155
|
+
def boolean( str )
|
156
|
+
::Libsql::Boolean.to_bool( str )
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# convert a string to a blob
|
161
|
+
#
|
162
|
+
def blob( str )
|
163
|
+
::Libsql::Blob.new( :string => str )
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
module ::Libsql::TypeMaps
|
7
|
+
##
|
8
|
+
# An Amalagliate TypeMap that has a one-to-one conversion between SQLite types
|
9
|
+
# and Ruby classes
|
10
|
+
#
|
11
|
+
class StorageMap < ::Libsql::TypeMap
|
12
|
+
##
|
13
|
+
# A straight logical mapping (for me at least) of basic Ruby classes to SQLite types, if
|
14
|
+
# nothing can be found then default to TEXT.
|
15
|
+
#
|
16
|
+
def bind_type_of( obj )
|
17
|
+
case obj
|
18
|
+
when Float
|
19
|
+
::Libsql::SQLite3::Constants::DataType::FLOAT
|
20
|
+
when Integer
|
21
|
+
::Libsql::SQLite3::Constants::DataType::INTEGER
|
22
|
+
when NilClass
|
23
|
+
::Libsql::SQLite3::Constants::DataType::NULL
|
24
|
+
when ::Libsql::Blob
|
25
|
+
::Libsql::SQLite3::Constants::DataType::BLOB
|
26
|
+
else
|
27
|
+
::Libsql::SQLite3::Constants::DataType::TEXT
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Do no mapping, just return the value as it was retrieved from SQLite.
|
33
|
+
#
|
34
|
+
def result_value_of( delcared_type, value )
|
35
|
+
return value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
#
|
6
|
+
|
7
|
+
module ::Libsql::TypeMaps
|
8
|
+
##
|
9
|
+
# An Amalagliate TypeMap that converts both bind parameters and result
|
10
|
+
# parameters to a String, no matter what.
|
11
|
+
#
|
12
|
+
class TextMap < ::Libsql::TypeMap
|
13
|
+
def bind_type_of( obj )
|
14
|
+
return ::Libsql::SQLite3::Constants::DataType::TEXT
|
15
|
+
end
|
16
|
+
|
17
|
+
def result_value_of( delcared_type, value )
|
18
|
+
return value.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/libsql/view.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
module ::Libsql
|
7
|
+
#
|
8
|
+
# a class representing the meta information about an SQLite view
|
9
|
+
#
|
10
|
+
class View
|
11
|
+
# the schame this view is assciated with
|
12
|
+
attr_accessor :schema
|
13
|
+
|
14
|
+
# the table name
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
# the original sql that was used to create this table
|
18
|
+
attr_reader :sql
|
19
|
+
|
20
|
+
def initialize( name, sql )
|
21
|
+
@name = name
|
22
|
+
@sql = sql
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/libsql-ruby.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative './libsql'
|
data/lib/libsql.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2023 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
# check if sqlite3 has already been required. ::Libsql conflicts with system
|
7
|
+
# level sqlite3 libraries.
|
8
|
+
unless $LOADED_FEATURES.grep( /\Asqlite3/ ).empty? then
|
9
|
+
raise LoadError, "libsql conflicts with sqlite3, please choose one or the other."
|
10
|
+
end
|
11
|
+
|
12
|
+
module ::Libsql
|
13
|
+
#
|
14
|
+
# Base class of all errors in ::Libsql
|
15
|
+
#
|
16
|
+
class Error < ::StandardError; end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Load the binary extension, try loading one for the specific version of ruby
|
20
|
+
# and if that fails, then fall back to one in the top of the library.
|
21
|
+
# this is the method recommended by rake-compiler
|
22
|
+
begin
|
23
|
+
# this will be for windows
|
24
|
+
require "libsql/#{RUBY_VERSION.sub(/\.\d+$/,'')}/libsql_ext"
|
25
|
+
rescue LoadError
|
26
|
+
# everyone else.
|
27
|
+
require 'libsql/libsql_ext'
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
require 'libsql/aggregate'
|
32
|
+
require 'libsql/blob'
|
33
|
+
require 'libsql/boolean'
|
34
|
+
require 'libsql/busy_timeout'
|
35
|
+
require 'libsql/column'
|
36
|
+
require 'libsql/database'
|
37
|
+
require 'libsql/function'
|
38
|
+
require 'libsql/index'
|
39
|
+
require 'libsql/memory_database'
|
40
|
+
require 'libsql/paths'
|
41
|
+
require 'libsql/profile_tap'
|
42
|
+
require 'libsql/progress_handler'
|
43
|
+
require 'libsql/schema'
|
44
|
+
require 'libsql/sqlite3'
|
45
|
+
require 'libsql/statement'
|
46
|
+
require 'libsql/table'
|
47
|
+
require 'libsql/taps'
|
48
|
+
require 'libsql/trace_tap'
|
49
|
+
require 'libsql/type_map'
|
50
|
+
require 'libsql/version'
|
51
|
+
require 'libsql/view'
|