datomic-flare 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../logic/transacting'
4
+ require_relative '../../logic/types'
5
+
6
+ module Flare
7
+ module DSLTransacting
8
+ def retract_from!(namespace, data, database: nil, debug: nil)
9
+ transaction_data = data.is_a?(Array) ? data : [data]
10
+
11
+ transaction_data = TransactingLogic.retractions_to_edn(
12
+ namespace, transaction_data
13
+ )
14
+
15
+ payload = { data: transaction_data }
16
+
17
+ payload[:connection] = { database: { name: database } } unless database.nil?
18
+
19
+ response = client.api.transact!(payload, debug:)
20
+
21
+ debug ? response : true
22
+ end
23
+
24
+ def assert_into!(namespace, data, database: nil, raw: nil, debug: nil)
25
+ transaction_data = data.is_a?(Array) ? data : [data]
26
+
27
+ ids = {}
28
+
29
+ # Within the scope of a single transaction, tempids map consistently
30
+ # to permanent ids. Values of n from -1 to -1000000, inclusive, are
31
+ # reserved for user-created tempids.
32
+ transaction_data = transaction_data.map.with_index do |fact, i|
33
+ if fact.key?(:_id)
34
+ ids[fact[:_id]] = fact[:_id]
35
+ fact
36
+ else
37
+ temporary_id = (i + 1) * -1
38
+ ids[temporary_id] = nil
39
+ fact.merge({ _temporary_id: temporary_id })
40
+ end
41
+ end
42
+
43
+ transaction_data = TransactingLogic.transactions_to_edn(
44
+ namespace, transaction_data
45
+ )
46
+
47
+ payload = { data: transaction_data }
48
+
49
+ payload[:connection] = { database: { name: database } } unless database.nil?
50
+
51
+ result = client.api.transact!(payload, debug:)
52
+
53
+ return result if debug || raw
54
+
55
+ result['data']['tempids'].map do |temporary_id, entity_id|
56
+ ids[temporary_id.to_i] = entity_id
57
+ end
58
+
59
+ data.is_a?(Array) ? ids.values : ids.values.first
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'dsl/schema'
4
+ require_relative 'dsl/transacting'
5
+ require_relative 'dsl/querying'
6
+
7
+ module Flare
8
+ class DSL
9
+ include DSLQuerying
10
+ include DSLSchema
11
+ include DSLTransacting
12
+
13
+ attr_reader :client, :api
14
+
15
+ def initialize(client)
16
+ @client = client
17
+ @api = client.api
18
+ end
19
+
20
+ def create_database!(database_name, debug: nil)
21
+ result = api.create_database!(
22
+ { name: database_name }, debug:
23
+ )
24
+
25
+ debug ? result : result['data']
26
+ end
27
+
28
+ def destroy_database!(database_name, debug: nil)
29
+ result = api.delete_database!(
30
+ { name: database_name }, debug:
31
+ )
32
+
33
+ debug ? result : result['data']
34
+ end
35
+
36
+ def databases(mode:, debug: nil)
37
+ mode = client.meta['meta']['mode'] if mode.nil?
38
+
39
+ response = if mode == 'peer'
40
+ client.api.get_database_names(debug:)
41
+ else
42
+ client.api.list_databases(debug:)
43
+ end
44
+
45
+ debug ? response : response['data']
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'static/gem'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = Flare::GEM[:name]
7
+ spec.version = Flare::GEM[:version]
8
+ spec.authors = [Flare::GEM[:author]]
9
+
10
+ spec.summary = Flare::GEM[:summary]
11
+ spec.description = Flare::GEM[:description]
12
+
13
+ spec.homepage = Flare::GEM[:github]
14
+
15
+ spec.license = Flare::GEM[:license]
16
+
17
+ spec.required_ruby_version = Gem::Requirement.new(">= #{Flare::GEM[:ruby]}")
18
+
19
+ spec.metadata['allowed_push_host'] = Flare::GEM[:gem_server]
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = Flare::GEM[:github]
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{\A(?:test|spec|features)/})
27
+ end
28
+ end
29
+
30
+ spec.require_paths = ['ports/dsl']
31
+
32
+ spec.add_dependency 'faraday', '~> 2.12'
33
+ spec.add_dependency 'faraday-typhoeus', '~> 1.1'
34
+ spec.add_dependency 'typhoeus', '~> 1.4', '>= 1.4.1'
35
+
36
+ spec.add_dependency 'uuidx', '~> 0.10.0'
37
+
38
+ spec.metadata['rubygems_mfa_required'] = 'true'
39
+ end