wowsql-sdk 1.2.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,15 +44,67 @@ 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)
39
51
  @client.request('POST', "/#{@table_name}", nil, data)
40
52
  end
41
53
 
54
+ # Insert a new record (alias for create).
55
+ #
56
+ # @param data [Hash] Record data
57
+ # @return [Hash] Create response with new record ID
58
+ def insert(data)
59
+ create(data)
60
+ end
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
+
42
106
  # Update a record by ID.
43
- #
107
+ #
44
108
  # @param record_id [Object] Record ID
45
109
  # @param data [Hash] Data to update
46
110
  # @return [Hash] Update response
@@ -49,12 +113,57 @@ module WOWSQL
49
113
  end
50
114
 
51
115
  # Delete a record by ID.
52
- #
116
+ #
53
117
  # @param record_id [Object] Record ID
54
118
  # @return [Hash] Delete response
55
119
  def delete(record_id)
56
120
  @client.request('DELETE', "/#{@table_name}/#{record_id}", nil, nil)
57
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
58
168
  end
59
169
  end
60
-
@@ -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
@@ -3,8 +3,9 @@ require_relative 'wowsql/exceptions'
3
3
  require_relative 'wowsql/client'
4
4
  require_relative 'wowsql/table'
5
5
  require_relative 'wowsql/query_builder'
6
+ require_relative 'wowsql/auth'
7
+ require_relative 'wowsql/storage'
8
+ require_relative 'wowsql/schema'
6
9
 
7
10
  module WOWSQL
8
- # Main module for WOWSQL SDK
9
11
  end
10
-
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.2.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: []
@@ -77,9 +91,12 @@ files:
77
91
  - README.md
78
92
  - lib/wowmysql.rb
79
93
  - lib/wowsql.rb
94
+ - lib/wowsql/auth.rb
80
95
  - lib/wowsql/client.rb
81
96
  - lib/wowsql/exceptions.rb
82
97
  - lib/wowsql/query_builder.rb
98
+ - lib/wowsql/schema.rb
99
+ - lib/wowsql/storage.rb
83
100
  - lib/wowsql/table.rb
84
101
  - lib/wowsql/version.rb
85
102
  homepage: https://github.com/wowsql/wowsql-sdk-ruby
@@ -100,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
117
  - !ruby/object:Gem::Version
101
118
  version: '0'
102
119
  requirements: []
103
- rubygems_version: 3.6.9
120
+ rubygems_version: 4.0.2
104
121
  specification_version: 4
105
- summary: Official Ruby client library for WOWSQL - MySQL Backend-as-a-Service with
106
- S3 Storage
122
+ summary: Official Ruby client library for WOWSQL - PostgreSQL Backend-as-a-Service
123
+ with Object Storage
107
124
  test_files: []