gqlite 0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,6 +80,11 @@ void gqlite_value_destroy(gqlite_api_context_t, gqlite_value_t);
80
80
  */
81
81
  const char* gqlite_value_to_json(gqlite_api_context_t, gqlite_value_t);
82
82
 
83
+ /**
84
+ * Create value from json.
85
+ */
86
+ gqlite_value_t gqlite_value_from_json(gqlite_api_context_t, const char*);
87
+
83
88
  /**
84
89
  * Check if the value is valid.
85
90
  */
data/ext/gqlite/gqlite.h CHANGED
@@ -10,44 +10,35 @@ namespace gqlite
10
10
  {
11
11
  class backend;
12
12
  struct debug_stats;
13
+ enum class exception_stage;
14
+ enum class exception_code;
15
+ struct exception_maker;
16
+ struct exception_reader;
13
17
  /**
14
18
  * Represents an error that occurs during the execution of a query.
15
19
  */
16
20
  class exception : public std::exception
17
21
  {
22
+ friend class exception_maker;
23
+ friend class exception_reader;
18
24
  public:
19
- exception(const std::string& _error) : m_error(_error), m_c_error(m_error.c_str()) {}
20
- exception(const char* _error) : m_c_error(_error) {}
21
- template<typename _T_, typename... _TOther_>
22
- inline exception(const char* _format, const _T_& _value, const _TOther_&... _other);
23
- template<typename _T_, typename... _TOther_>
24
- inline exception(const std::string& _format, const _T_& _value, const _TOther_&... _other);
25
+ exception(exception&& _rhs);
25
26
  exception(const exception& _rhs);
26
27
  exception& operator=(const exception& _rhs);
28
+ ~exception();
27
29
  /**
28
30
  * @return the error message
29
31
  */
30
- const char* what() const throw() override
31
- {
32
- return m_c_error;
33
- }
32
+ const char* what() const throw() override;
34
33
  private:
35
- std::string m_error;
36
- const char* m_c_error;
34
+ struct data;
35
+ exception(data* _d);
36
+ data* const d;
37
37
  };
38
38
  /**
39
39
  * Represent the value type.
40
40
  */
41
- enum class value_type
42
- {
43
- invalid,
44
- boolean,
45
- integer,
46
- number, ///< aka float
47
- string,
48
- map,
49
- vector
50
- };
41
+ enum class value_type;
51
42
  class value;
52
43
  using value_map = std::unordered_map<std::string, value>;
53
44
  using value_vector = std::vector<value>;
@@ -62,8 +53,10 @@ namespace gqlite
62
53
  value& operator=(const value& _rhs);
63
54
  ~value();
64
55
  public:
65
- value(int _v);
56
+ value(bool _v);
57
+ value(int64_t _v);
66
58
  value(double _v);
59
+ value(const char* _v);
67
60
  value(const std::string& _v);
68
61
  value(const value_map& _v);
69
62
  /// not part of the public API
@@ -74,6 +67,7 @@ namespace gqlite
74
67
  template<typename _T_>
75
68
  value(const std::vector<_T_>& _v);
76
69
  bool operator==(const value& _rhs) const;
70
+ bool operator<(const value& _rhs) const;
77
71
  public:
78
72
  /**
79
73
  * @return the type hold by this value
@@ -86,7 +80,7 @@ namespace gqlite
86
80
  /**
87
81
  * Attempt to return an integer. Throw an exception if not possible.
88
82
  */
89
- int to_integer() const;
83
+ int64_t to_integer() const;
90
84
  /**
91
85
  * Attempt to return a double. Throw an exception if not possible.
92
86
  */
@@ -135,11 +129,6 @@ namespace gqlite
135
129
  * Create a sqlite connection from a file.
136
130
  */
137
131
  static connection create_from_sqlite_file(const std::string& _filename, const value& _options = value());
138
- /**
139
- * @internal
140
- * Part of the private API, what is returned by this function may change at any time.
141
- */
142
- gqlite::value get_debug_stats() const;
143
132
  public:
144
133
  /**
145
134
  * Execute a query.
data/lib/gqlite.rb CHANGED
@@ -2,12 +2,22 @@ require 'ffi'
2
2
  require 'objspace'
3
3
  require 'json'
4
4
 
5
- module Gqlite
5
+ module GQLite
6
6
  class Error < StandardError
7
7
  end
8
8
  module CApi
9
9
  extend FFI::Library
10
- ffi_lib 'gqlite'
10
+
11
+ # Attempt to find the gqlite build that is shipped with gem
12
+ def CApi.get_lib_name()
13
+ path = "#{File.dirname __FILE__}/#{FFI::Platform::LIBPREFIX}gqlite.#{FFI::Platform::LIBSUFFIX}"
14
+ return path if File.exist?(path)
15
+ path = "#{File.dirname __FILE__}/gqlite.#{FFI::Platform::LIBSUFFIX}"
16
+ return path if File.exist?(path)
17
+ return "gqlite"
18
+ end
19
+
20
+ ffi_lib CApi.get_lib_name()
11
21
  attach_function :gqlite_api_context_create, [], :pointer
12
22
  attach_function :gqlite_api_context_destroy, [:pointer], :void
13
23
  attach_function :gqlite_api_context_clear_error, [:pointer], :void
@@ -19,13 +29,14 @@ module Gqlite
19
29
  attach_function :gqlite_value_create, [:pointer], :pointer
20
30
  attach_function :gqlite_value_destroy, [:pointer, :pointer], :void
21
31
  attach_function :gqlite_value_to_json, [:pointer, :pointer], :string
32
+ attach_function :gqlite_value_from_json, [:pointer, :string], :pointer
22
33
  attach_function :gqlite_value_is_valid, [:pointer, :pointer], :bool
23
- ApiError = CApi.gqlite_api_context_create()
34
+ ApiContext = CApi.gqlite_api_context_create()
24
35
  def CApi.call_function(fname, *args)
25
- r = CApi.send fname, ApiError, *args
26
- if CApi.gqlite_api_context_has_error(ApiError)
27
- err = CApi.gqlite_api_context_get_message ApiError
28
- CApi.gqlite_api_context_clear_error ApiError
36
+ r = CApi.send fname, ApiContext, *args
37
+ if CApi.gqlite_api_context_has_error(ApiContext)
38
+ err = CApi.gqlite_api_context_get_message ApiContext
39
+ CApi.gqlite_api_context_clear_error ApiContext
29
40
  raise Error.new err
30
41
  end
31
42
  return r
@@ -44,11 +55,18 @@ module Gqlite
44
55
  }
45
56
  end
46
57
  def execute_oc_query(query, bindings: nil)
47
- ret = CApi.call_function :gqlite_connection_oc_query, @dbhandle, query, nil
58
+ b = nil
59
+ if bindings
60
+ b = CApi.call_function :gqlite_value_from_json, bindings.to_json
61
+ end
62
+ ret = CApi.call_function :gqlite_connection_oc_query, @dbhandle, query, b
63
+ if b
64
+ CApi.call_function :gqlite_value_destroy, b
65
+ end
48
66
  if CApi.call_function(:gqlite_value_is_valid, ret)
49
- val = JSON.parse CApi.call_function :gqlite_value_to_json, ret
67
+ val = JSON.parse(CApi.call_function :gqlite_value_to_json, ret)
50
68
  else
51
- ret = nil
69
+ val = nil
52
70
  end
53
71
  CApi.call_function :gqlite_value_destroy, ret
54
72
  return val
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gqlite
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyrille Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2024-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,11 +24,26 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.15'
27
- description: |2
28
- GQLite aims to be the equivalent to SQLite for graph database: an easy to embedd query engine, with the data stored in a single file. To achieve that, GQLite uses SQLite to store data, and come as a library implementing a translation between graph query languages and SQL.
29
-
30
- This is an experimental release.
31
- email:
27
+ description: "GQLite is a C++-language library, with a C interface, that implements
28
+ a small, fast, self-contained, high-reliability, full-featured, Graph Query database
29
+ engine. The data is stored in a SQLite database, which the fasted and most used
30
+ SQL database. This enable to achieve high performance and for application to combine
31
+ Graph queries with traditional SQL queries.\n\nGQLite source code is license under
32
+ the [MIT License](LICENSE) and is free to everyone to use for any purpose. \n\nThe
33
+ official repositories contains bindings/APIs for C, C++, Python, Ruby and Crystal.\n\nThe
34
+ library is still in its early stage, but it is now fully functional. Development
35
+ effort has now slowed down and new features are added on a by-need basis. It supports
36
+ a subset of [OpenCypher](https://opencypher.org/), and the intent is to also support
37
+ ISO GQL in the future when it become available.\n \nExample of use\n--------------\n\n```ruby\nrequire
38
+ 'gqlite'\n\nbegin\n # Create a database on the file \"test.db\"\n connection =
39
+ GQLite::Connection.new sqlite_filename: \"test.db\"\n\n # Execute a simple query
40
+ to create a node and return all the nodes\n value = connection.execute_oc_query(\"CREATE
41
+ () MATCH (n) RETURN n\")\n\n # Print the result\n if value.nil?\n puts \"Empty
42
+ results\"\n else\n puts \"Results are #{value.to_s}\"\n end\nrescue GQLite::Error
43
+ => ex\n # Report any error\n puts \"An error has occured: #{ex.message}\"\nend\n\n```\n\nThe
44
+ documentation for the openCypher query language can found in [openCypher](https://gitlab.com/gqlite/GQLite/-/blob/docs/opencypher.md)
45
+ and for the [API](https://gitlab.com/gqlite/GQLite/-/blob/docs/api.md).\n\n"
46
+ email:
32
47
  executables: []
33
48
  extensions:
34
49
  - ext/gqlite/extconf.rb
@@ -39,11 +54,11 @@ files:
39
54
  - ext/gqlite/gqlite-c.h
40
55
  - ext/gqlite/gqlite.h
41
56
  - lib/gqlite.rb
42
- homepage: https://gitlab.com/cyloncore/gqlite
57
+ homepage: https://gitlab.com/gqlite/gqlite
43
58
  licenses:
44
59
  - MIT
45
60
  metadata: {}
46
- post_install_message:
61
+ post_install_message:
47
62
  rdoc_options: []
48
63
  require_paths:
49
64
  - lib
@@ -58,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
73
  - !ruby/object:Gem::Version
59
74
  version: '0'
60
75
  requirements: []
61
- rubygems_version: 3.3.5
62
- signing_key:
76
+ rubygems_version: 3.4.20
77
+ signing_key:
63
78
  specification_version: 4
64
79
  summary: Ruby bindings for GQLite, a Graph Query library.
65
80
  test_files: []