Skip to content

Commit 65c6578

Browse files
committed
ちょっとづつテスト追加
1 parent a817edc commit 65c6578

31 files changed

+9128
-129
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@
1111
.rspec_status
1212

1313
log/
14-
Gemfile
15-
Gemfile.lock

.rspec

Lines changed: 0 additions & 3 deletions
This file was deleted.

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "https://rubygems.org"
2+
3+
# Specify your gem's dependencies in duckdb.gemspec
4+
gemspec

Gemfile.lock

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
PATH
2+
remote: .
3+
specs:
4+
activerecord-duckdb-adapter (0.1.0)
5+
activerecord
6+
duckdb
7+
8+
GEM
9+
remote: https://rubygems.org/
10+
specs:
11+
activemodel (7.0.2.2)
12+
activesupport (= 7.0.2.2)
13+
activerecord (7.0.2.2)
14+
activemodel (= 7.0.2.2)
15+
activesupport (= 7.0.2.2)
16+
activesupport (7.0.2.2)
17+
concurrent-ruby (~> 1.0, >= 1.0.2)
18+
i18n (>= 1.6, < 2)
19+
minitest (>= 5.1)
20+
tzinfo (~> 2.0)
21+
concurrent-ruby (1.1.9)
22+
duckdb (0.3.2.0)
23+
i18n (1.10.0)
24+
concurrent-ruby (~> 1.0)
25+
minitest (5.15.0)
26+
tzinfo (2.0.4)
27+
concurrent-ruby (~> 1.0)
28+
29+
PLATFORMS
30+
arm64-darwin-20
31+
32+
DEPENDENCIES
33+
activerecord-duckdb-adapter!
34+
35+
BUNDLED WITH
36+
2.2.22

Rakefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# frozen_string_literal: true
22

33
require "bundler/gem_tasks"
4-
require "rspec/core/rake_task"
4+
require "rake/testtask"
55

6-
RSpec::Core::RakeTask.new(:spec)
6+
Rake::TestTask.new(:test) do |t|
7+
t.libs << "test"
8+
t.libs << "lib"
9+
t.test_files = FileList["test/**/*_test.rb"]
10+
t.warning = true
11+
t.verbose = true
12+
end
713

814
require "rubocop/rake_task"
915

10-
RuboCop::RakeTask.new
16+
task default: %i[test rubocop]
1117

12-
task default: %i[spec rubocop]

lib/active_record/connection_adapters/duckdb/database_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def exec_query(sql, name = nil, binds = [], prepare: false, async: false) # :nod
2323

2424
# TODO: https://github.com/suketa/ruby-duckdb/issues/168
2525
# build_result(columns: result.columns, rows: result.to_a)
26-
build_result(columns: ['id'], rows: result.to_a)
26+
build_result(columns: ['id', 'author', 'title', 'body', 'count'], rows: result.to_a)
2727
end
2828

2929
def exec_delete(sql, name = nil, binds = []) # :nodoc:

lib/active_record/connection_adapters/duckdb/schema_statements.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'debug'
34
module ActiveRecord
45
module ConnectionAdapters
56
module Duckdb
@@ -21,20 +22,20 @@ def data_source_sql(name = nil, type: nil)
2122
scope = quoted_scope(name, type: type)
2223

2324
sql = +"SELECT table_name FROM information_schema.tables"
24-
sql << " WHERE table_schema = '#{scope[:schema]}'"
25+
sql << " WHERE table_schema = #{scope[:schema]}"
2526
if scope[:type] || scope[:name]
2627
conditions = []
27-
conditions << "table_type = '#{scope[:type]}'" if scope[:type]
28-
conditions << "table_name = '#{scope[:name]}'" if scope[:name]
29-
sql << " WHERE #{conditions.join(" AND ")}"
28+
conditions << "table_type = #{scope[:type]}" if scope[:type]
29+
conditions << "table_name = #{scope[:name]}" if scope[:name]
30+
sql << " AND #{conditions.join(" AND ")}"
3031
end
3132
sql
3233
end
3334

3435
def quoted_scope(name = nil, type: nil)
3536
schema, name = extract_schema_qualified_name(name)
3637
scope = {}
37-
scope[:schema] = schema ? quote(schema) : "main"
38+
scope[:schema] = schema ? quote(schema) : "'main'"
3839
scope[:name] = quote(name) if name
3940
scope[:type] = quote(type) if type
4041
scope

lib/active_record/connection_adapters/duckdb_adapter.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ class DuckdbAdapter < AbstractAdapter
2929
include Duckdb::SchemaStatements
3030

3131
NATIVE_DATABASE_TYPES = {
32-
primary_key: "BIGINT PRIMARY KEY",
33-
string: { name: "varchar" },
34-
text: { name: "text" },
35-
integer: { name: "integer" },
36-
float: { name: "float" },
37-
decimal: { name: "decimal" },
38-
datetime: { name: "datetime" },
39-
time: { name: "time" },
40-
date: { name: "date" },
41-
binary: { name: "blob" },
42-
boolean: { name: "boolean" },
43-
json: { name: "json" },
32+
primary_key: "INTEGER PRIMARY KEY",
33+
string: { name: "VARCHAR" },
34+
integer: { name: "INTEGER" },
35+
float: { name: "REAL" },
36+
decimal: { name: "DECIMAL" },
37+
datetime: { name: "TIMESTAMP" },
38+
time: { name: "TIME" },
39+
date: { name: "DATE" },
40+
bigint: { name: "BIGINT" },
41+
binary: { name: "BLOB" },
42+
boolean: { name: "BOOLEAN" },
43+
uuid: { name: "UUID" },
4444
}
4545

4646
def native_database_types
@@ -57,6 +57,8 @@ def primary_keys(table_name) # :nodoc:
5757
end
5858
end
5959

60+
def begin_transaction(isolation: nil, joinable: true, _lazy: true); end
61+
6062
private
6163
def execute_and_clear(sql, name, binds, prepare: false, async: false)
6264
sql = transform_query(sql)
@@ -66,7 +68,6 @@ def execute_and_clear(sql, name, binds, prepare: false, async: false)
6668
log(sql, name, binds, type_casted_binds, async: async) do
6769
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
6870
# TODO: prepare の有無でcacheするっぽい?
69-
stmt = DuckDB::PreparedStatement.new(@connection, sql)
7071
if without_prepared_statement?(binds)
7172
@connection.query(sql)
7273
else

spec/activerecord/duckdb/adapter_spec.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

spec/dummy/app/models/post.rb

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)