wowsql-sdk 1.3.0 → 3.0.1

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.
data/lib/wowsql/table.rb CHANGED
@@ -9,22 +9,34 @@ module WOWSQL
9
9
  end
10
10
 
11
11
  # Start a query with column selection.
12
- #
12
+ #
13
13
  # @param columns [Array<String>] Column(s) to select
14
14
  # @return [QueryBuilder] QueryBuilder for chaining
15
15
  def select(*columns)
16
16
  QueryBuilder.new(@client, @table_name).select(*columns)
17
17
  end
18
18
 
19
+ # Start a query with a filter.
20
+ #
21
+ # @param column [String, Hash] Column name or filter hash
22
+ # @param operator [String, nil] Operator
23
+ # @param value [Object] Filter value
24
+ # @param logical_op [String] "AND" or "OR"
25
+ # @return [QueryBuilder] QueryBuilder for chaining
26
+ def filter(column, operator = nil, value = nil, logical_op: 'AND')
27
+ QueryBuilder.new(@client, @table_name).filter(column, operator, value, logical_op: logical_op)
28
+ end
29
+
19
30
  # Get all records with optional filters.
20
- #
31
+ #
32
+ # @param options [Hash, nil] Query options
21
33
  # @return [Hash] Query response
22
- def get
23
- QueryBuilder.new(@client, @table_name).get
34
+ def get(options = nil)
35
+ QueryBuilder.new(@client, @table_name).get(options)
24
36
  end
25
37
 
26
38
  # Get a single record by ID.
27
- #
39
+ #
28
40
  # @param record_id [Object] Record ID
29
41
  # @return [Hash] Record data
30
42
  def get_by_id(record_id)
@@ -32,7 +44,7 @@ module WOWSQL
32
44
  end
33
45
 
34
46
  # Create a new record.
35
- #
47
+ #
36
48
  # @param data [Hash] Record data
37
49
  # @return [Hash] Create response with new record ID
38
50
  def create(data)
@@ -40,15 +52,59 @@ module WOWSQL
40
52
  end
41
53
 
42
54
  # Insert a new record (alias for create).
43
- #
55
+ #
44
56
  # @param data [Hash] Record data
45
57
  # @return [Hash] Create response with new record ID
46
58
  def insert(data)
47
59
  create(data)
48
60
  end
49
61
 
62
+ # Insert multiple records.
63
+ #
64
+ # Attempts a single batch POST first. Falls back to individual
65
+ # inserts if the server does not support batch creation.
66
+ #
67
+ # @param records [Array<Hash>] List of record hashes
68
+ # @return [Array<Hash>] List of create responses
69
+ def bulk_insert(records)
70
+ return [] if records.nil? || records.empty?
71
+
72
+ begin
73
+ result = @client.request('POST', "/#{@table_name}", nil, records)
74
+ result.is_a?(Array) ? result : [result]
75
+ rescue StandardError
76
+ records.map { |record| create(record) }
77
+ end
78
+ end
79
+
80
+ # Insert or update based on conflict column.
81
+ #
82
+ # Uses PostgreSQL ON CONFLICT (upsert). Falls back to
83
+ # get-then-insert/update when the backend doesn't expose
84
+ # a native upsert endpoint.
85
+ #
86
+ # @param data [Hash] Record data (must include the conflict column)
87
+ # @param on_conflict [String] Column to check for conflicts (default: "id")
88
+ # @return [Hash] Create or update response
89
+ def upsert(data, on_conflict: 'id')
90
+ conflict_value = data[on_conflict] || data[on_conflict.to_sym]
91
+ return create(data) if conflict_value.nil?
92
+
93
+ existing = QueryBuilder.new(@client, @table_name).eq(on_conflict, conflict_value).first
94
+ if existing
95
+ update_data = data.reject { |k, _| k.to_s == on_conflict }
96
+ if update_data.empty?
97
+ { 'message' => 'No changes', 'affected_rows' => 0 }
98
+ else
99
+ update(conflict_value, update_data)
100
+ end
101
+ else
102
+ create(data)
103
+ end
104
+ end
105
+
50
106
  # Update a record by ID.
51
- #
107
+ #
52
108
  # @param record_id [Object] Record ID
53
109
  # @param data [Hash] Data to update
54
110
  # @return [Hash] Update response
@@ -57,12 +113,57 @@ module WOWSQL
57
113
  end
58
114
 
59
115
  # Delete a record by ID.
60
- #
116
+ #
61
117
  # @param record_id [Object] Record ID
62
118
  # @return [Hash] Delete response
63
119
  def delete(record_id)
64
120
  @client.request('DELETE', "/#{@table_name}/#{record_id}", nil, nil)
65
121
  end
122
+
123
+ # ── Convenience shortcuts ──────────────────────────────────
124
+
125
+ def eq(column, value)
126
+ QueryBuilder.new(@client, @table_name).eq(column, value)
127
+ end
128
+
129
+ def neq(column, value)
130
+ QueryBuilder.new(@client, @table_name).neq(column, value)
131
+ end
132
+
133
+ def gt(column, value)
134
+ QueryBuilder.new(@client, @table_name).gt(column, value)
135
+ end
136
+
137
+ def gte(column, value)
138
+ QueryBuilder.new(@client, @table_name).gte(column, value)
139
+ end
140
+
141
+ def lt(column, value)
142
+ QueryBuilder.new(@client, @table_name).lt(column, value)
143
+ end
144
+
145
+ def lte(column, value)
146
+ QueryBuilder.new(@client, @table_name).lte(column, value)
147
+ end
148
+
149
+ def order_by(column, direction = 'asc')
150
+ QueryBuilder.new(@client, @table_name).order_by(column, direction)
151
+ end
152
+
153
+ # Get total record count for this table.
154
+ #
155
+ # @return [Integer]
156
+ def count
157
+ QueryBuilder.new(@client, @table_name).count
158
+ end
159
+
160
+ # Paginate all records in this table.
161
+ #
162
+ # @param page [Integer] Page number (1-indexed)
163
+ # @param per_page [Integer] Records per page
164
+ # @return [Hash]
165
+ def paginate(page: 1, per_page: 20)
166
+ QueryBuilder.new(@client, @table_name).paginate(page: page, per_page: per_page)
167
+ end
66
168
  end
67
169
  end
68
-
@@ -1,4 +1,4 @@
1
1
  module WOWSQL
2
- VERSION = "1.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
4
4
 
data/lib/wowsql.rb CHANGED
@@ -4,8 +4,8 @@ require_relative 'wowsql/client'
4
4
  require_relative 'wowsql/table'
5
5
  require_relative 'wowsql/query_builder'
6
6
  require_relative 'wowsql/auth'
7
+ require_relative 'wowsql/storage'
8
+ require_relative 'wowsql/schema'
7
9
 
8
10
  module WOWSQL
9
- # Main module for WOWSQL SDK
10
11
  end
11
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wowsql-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WOWSQL Team
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday-multipart
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: json
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -65,8 +79,8 @@ dependencies:
65
79
  - - "~>"
66
80
  - !ruby/object:Gem::Version
67
81
  version: '13.0'
68
- description: Official Ruby client library for WOWSQL - MySQL Backend-as-a-Service
69
- with S3 Storage
82
+ description: Official Ruby client library for WOWSQL - PostgreSQL Backend-as-a-Service
83
+ with Object Storage
70
84
  email:
71
85
  - support@wowsql.com
72
86
  executables: []
@@ -81,6 +95,7 @@ files:
81
95
  - lib/wowsql/client.rb
82
96
  - lib/wowsql/exceptions.rb
83
97
  - lib/wowsql/query_builder.rb
98
+ - lib/wowsql/schema.rb
84
99
  - lib/wowsql/storage.rb
85
100
  - lib/wowsql/table.rb
86
101
  - lib/wowsql/version.rb
@@ -104,6 +119,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
119
  requirements: []
105
120
  rubygems_version: 4.0.2
106
121
  specification_version: 4
107
- summary: Official Ruby client library for WOWSQL - MySQL Backend-as-a-Service with
108
- S3 Storage
122
+ summary: Official Ruby client library for WOWSQL - PostgreSQL Backend-as-a-Service
123
+ with Object Storage
109
124
  test_files: []