db-mariadb 0.5.0 → 0.8.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '035816431be310fe0576e3484d8567531a899ac9b5bde00ef6eae5f40d835c10'
4
- data.tar.gz: 26e1ab9017bb812343fc61e98d2d23c1f197e4b7a5bcea97b2809a61df61bd6d
3
+ metadata.gz: da745fa5ee09cf5597517b05fed1addde79acd2806e7100478fc53c9bb17cb0a
4
+ data.tar.gz: af66b7b339684d530a30c698554c8bf44c3db0190bf2d65c947d7fa2ba012cda
5
5
  SHA512:
6
- metadata.gz: 6d858c2bd63c590f05b12df2ee6f5fba4551c77fd668143a42d548a1d52ec6d5725fa4d94e9df235266d73996f8b31d5a4cd4bb1451cd59c1544e38825337ac6
7
- data.tar.gz: 9becfe75e0c743be9c765904eaabf2f52b757d6532db7a04a7381414c4532496233c7dcf398ca23d681494b4f61258dc6db5653b6459b88f617582d0abe47e47
6
+ metadata.gz: 28697c26a2fa1336a7902510fcf89815b1b8092ce9e109ba376321ea4ab12c66e19ef6c5bf9490a57259bc0452c3e9c70bebef62a8694f8e76388a793b6eb9c8
7
+ data.tar.gz: de7b57100c80451e8192a7b0b4f59635fa2b7ee0ecac8c305c08be4cbb1fe0fc3f920d3d68d6d695856855759377175790760e75145fa22a7316b45991c26802
data/lib/.DS_Store ADDED
Binary file
@@ -24,8 +24,6 @@ require_relative 'connection'
24
24
 
25
25
  module DB
26
26
  module MariaDB
27
- LOCAL = "mysql://localhost/test"
28
-
29
27
  class Adapter
30
28
  def initialize(**options)
31
29
  @options = options
@@ -65,20 +65,33 @@ module DB
65
65
  end
66
66
 
67
67
  def append_identifier(value, buffer = String.new)
68
- buffer << "`" << @native.escape(value) << "`"
68
+ case value
69
+ when Array
70
+ first = true
71
+ value.each do |part|
72
+ buffer << '.' unless first
73
+ first = false
74
+
75
+ buffer << escape_identifier(part)
76
+ end
77
+ else
78
+ buffer << escape_identifier(value)
79
+ end
69
80
 
70
81
  return buffer
71
82
  end
72
83
 
73
- def id_column(name = 'id', primary_key: true)
84
+ def key_column(name = 'id', primary: true, null: false)
74
85
  buffer = String.new
75
86
 
76
87
  append_identifier(name, buffer)
77
88
 
78
- buffer << " BIGINT AUTO_INCREMENT"
89
+ buffer << " BIGINT"
79
90
 
80
- if primary_key
81
- buffer << " PRIMARY KEY"
91
+ if primary
92
+ buffer << " AUTO_INCREMENT PRIMARY KEY"
93
+ elsif !null
94
+ buffer << " NOT NULL"
82
95
  end
83
96
 
84
97
  return buffer
@@ -97,6 +110,12 @@ module DB
97
110
  def next_result
98
111
  @native.next_result
99
112
  end
113
+
114
+ protected
115
+
116
+ def escape_identifier(value)
117
+ "`#{@native.escape(value)}`"
118
+ end
100
119
  end
101
120
  end
102
121
  end
@@ -18,14 +18,40 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'ffi'
21
+ require 'ffi/module'
22
+ require 'ffi/module/config_tool'
22
23
 
23
24
  module DB
24
25
  module MariaDB
25
26
  module Native
26
- extend FFI::Library
27
+ extend FFI::Module::Library
28
+ extend FFI::Module::Loader
29
+ extend FFI::Module::ConfigTool
27
30
 
28
- ffi_lib 'mariadb'
31
+ ffi_load('mariadb') ||
32
+ ffi_load_using_config_tool(%w{mariadb_config --libs}) ||
33
+ ffi_load_using_config_tool(%w{mysql_config --libs}) ||
34
+ ffi_load_failure(<<~EOF)
35
+ Unable to load libmariadb!
36
+
37
+ ## Ubuntu
38
+
39
+ sudo apt-get install libmariadb-dev
40
+
41
+ ## Arch Linux
42
+
43
+ sudo pacman -S mariadb
44
+
45
+ ## MacPorts
46
+
47
+ sudo port install mariadb-10.5
48
+ sudo port select --set mysql mariadb-10.5
49
+
50
+ ## Homebrew
51
+
52
+ brew install mariadb
53
+
54
+ EOF
29
55
  end
30
56
  end
31
57
  end
@@ -24,6 +24,9 @@ require_relative '../error'
24
24
  module DB
25
25
  module MariaDB
26
26
  module Native
27
+ MYSQL_PROTOCOL_TCP = 1
28
+
29
+ MYSQL_OPT_PROTOCOL = 9
27
30
  MYSQL_OPT_NONBLOCK = 6000
28
31
 
29
32
  MYSQL_WAIT_READ = 1
@@ -36,32 +39,32 @@ module DB
36
39
  CLIENT_MULTI_STATEMENT = 0x00010000
37
40
  CLIENT_MULTI_RESULTS = 0x00020000
38
41
 
39
- attach_function :mysql_init, [:pointer], :pointer
40
- attach_function :mysql_options, [:pointer, :int, :pointer], :int
41
- attach_function :mysql_get_socket, [:pointer], :int
42
+ ffi_attach_function :mysql_init, [:pointer], :pointer
43
+ ffi_attach_function :mysql_options, [:pointer, :int, :pointer], :int
44
+ ffi_attach_function :mysql_get_socket, [:pointer], :int
42
45
 
43
- attach_function :mysql_real_connect_start, [:pointer, :pointer, :string, :string, :string, :string, :int, :string, :long], :int
44
- attach_function :mysql_real_connect_cont, [:pointer, :pointer, :int], :int
46
+ ffi_attach_function :mysql_real_connect_start, [:pointer, :pointer, :string, :string, :string, :string, :int, :string, :long], :int
47
+ ffi_attach_function :mysql_real_connect_cont, [:pointer, :pointer, :int], :int
45
48
 
46
- attach_function :mysql_real_query_start, [:pointer, :pointer, :string, :ulong], :int
47
- attach_function :mysql_real_query_cont, [:pointer, :pointer, :int], :int
49
+ ffi_attach_function :mysql_real_query_start, [:pointer, :pointer, :string, :ulong], :int
50
+ ffi_attach_function :mysql_real_query_cont, [:pointer, :pointer, :int], :int
48
51
 
49
- attach_function :mysql_use_result, [:pointer], :pointer
50
- attach_function :mysql_next_result, [:pointer], :int
51
- attach_function :mysql_more_results, [:pointer], :int
52
- attach_function :mysql_free_result, [:pointer], :void
52
+ ffi_attach_function :mysql_use_result, [:pointer], :pointer
53
+ ffi_attach_function :mysql_next_result, [:pointer], :int
54
+ ffi_attach_function :mysql_more_results, [:pointer], :int
55
+ ffi_attach_function :mysql_free_result, [:pointer], :void
53
56
 
54
- attach_function :mysql_affected_rows, [:pointer], :uint64
55
- attach_function :mysql_insert_id, [:pointer], :uint64
56
- attach_function :mysql_info, [:pointer], :string
57
+ ffi_attach_function :mysql_affected_rows, [:pointer], :uint64
58
+ ffi_attach_function :mysql_insert_id, [:pointer], :uint64
59
+ ffi_attach_function :mysql_info, [:pointer], :string
57
60
 
58
- attach_function :mysql_close, [:pointer], :void
59
- attach_function :mysql_errno, [:pointer], :uint
60
- attach_function :mysql_error, [:pointer], :string
61
+ ffi_attach_function :mysql_close, [:pointer], :void
62
+ ffi_attach_function :mysql_errno, [:pointer], :uint
63
+ ffi_attach_function :mysql_error, [:pointer], :string
61
64
 
62
- attach_function :mysql_stat, [:pointer], :string
65
+ ffi_attach_function :mysql_stat, [:pointer], :string
63
66
 
64
- attach_function :mysql_real_escape_string, [:pointer, :pointer, :string, :size_t], :size_t
67
+ ffi_attach_function :mysql_real_escape_string, [:pointer, :pointer, :string, :size_t], :size_t
65
68
 
66
69
  module IO
67
70
  def self.new(fd, mode)
@@ -70,10 +73,14 @@ module DB
70
73
  end
71
74
 
72
75
  class Connection < FFI::Pointer
73
- def self.connect(wrapper: IO, host: 'localhost', user: nil, password: nil, database: nil, port: 0, unix_socket: nil, client_flags: 0, compression: false, types: DEFAULT_TYPES, **options)
76
+ def self.connect(wrapper: IO, host: 'localhost', username: nil, password: nil, database: nil, port: 0, unix_socket: nil, client_flags: 0, compression: false, types: DEFAULT_TYPES, **options)
74
77
  pointer = Native.mysql_init(nil)
75
78
  Native.mysql_options(pointer, MYSQL_OPT_NONBLOCK, nil)
76
79
 
80
+ # if protocol
81
+ # Native.mysql_options(pointer, MYSQL_OPT_PROTOCOL, FFI::MemoryPointer.new(:uint, protocol))
82
+ # end
83
+
77
84
  client_flags |= CLIENT_MULTI_STATEMENT | CLIENT_MULTI_RESULTS
78
85
 
79
86
  if compression
@@ -82,7 +89,7 @@ module DB
82
89
 
83
90
  result = FFI::MemoryPointer.new(:pointer)
84
91
 
85
- status = Native.mysql_real_connect_start(result, pointer, host, user, password, database, port, unix_socket, client_flags);
92
+ status = Native.mysql_real_connect_start(result, pointer, host, username, password, database, port, unix_socket, client_flags);
86
93
 
87
94
  io = wrapper.new(Native.mysql_get_socket(pointer), "r+")
88
95
 
@@ -28,7 +28,7 @@ require 'json'
28
28
  module DB
29
29
  module MariaDB
30
30
  module Native
31
- Type = enum(
31
+ Type = ffi_define_enumeration(:field_type, [
32
32
  :decimal,
33
33
  :tiny,
34
34
  :short,
@@ -57,7 +57,7 @@ module DB
57
57
  :var_string,
58
58
  :string,
59
59
  :geometry,
60
- )
60
+ ])
61
61
 
62
62
  DEFAULT_TYPES = {
63
63
  decimal: Types::Decimal,
@@ -23,13 +23,13 @@ require_relative 'field'
23
23
  module DB
24
24
  module MariaDB
25
25
  module Native
26
- attach_function :mysql_fetch_row_start, [:pointer, :pointer], :int
27
- attach_function :mysql_fetch_row_cont, [:pointer, :pointer, :int], :int
26
+ ffi_attach_function :mysql_fetch_row_start, [:pointer, :pointer], :int
27
+ ffi_attach_function :mysql_fetch_row_cont, [:pointer, :pointer, :int], :int
28
28
 
29
- attach_function :mysql_num_rows, [:pointer], :uint64
30
- attach_function :mysql_num_fields, [:pointer], :uint32
29
+ ffi_attach_function :mysql_num_rows, [:pointer], :uint64
30
+ ffi_attach_function :mysql_num_fields, [:pointer], :uint32
31
31
 
32
- attach_function :mysql_fetch_fields, [:pointer], :pointer
32
+ ffi_attach_function :mysql_fetch_fields, [:pointer], :pointer
33
33
 
34
34
  class Result < FFI::Pointer
35
35
  def initialize(connection, types = {}, address)
@@ -109,6 +109,16 @@ module DB
109
109
  @connection.check_error!("Reading recordset")
110
110
  end
111
111
 
112
+ def map(&block)
113
+ results = []
114
+
115
+ self.each do |row|
116
+ results << yield row
117
+ end
118
+
119
+ return results
120
+ end
121
+
112
122
  def to_a
113
123
  rows = []
114
124
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module DB
22
22
  module MariaDB
23
- VERSION = "0.5.0"
23
+ VERSION = "0.8.2"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-mariadb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-06 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ffi
14
+ name: ffi-module
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: async-io
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,7 @@ executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - lib/.DS_Store
117
118
  - lib/db/mariadb.rb
118
119
  - lib/db/mariadb/adapter.rb
119
120
  - lib/db/mariadb/connection.rb
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
145
146
  requirements: []
146
- rubygems_version: 3.1.2
147
+ rubygems_version: 3.2.3
147
148
  signing_key:
148
149
  specification_version: 4
149
150
  summary: An event-driven interface for MariaDB and MySQL servers.