TestDB: initial commit.

This commit is contained in:
Philippe PITTOLI 2024-05-06 14:36:36 +02:00
commit c2f531bae4
6 changed files with 65 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# test-db
Simple database tests to compare DODB to SQL (Postgres).

21
shard.yml Normal file
View File

@ -0,0 +1,21 @@
name: test-db
version: 0.1.0
authors:
- Philippe PITTOLI <karchnu@karchnu.fr>
targets:
psql-query-one:
main: src/psql-query-one.cr
# test-db:
# main: src/test-db.cr
dependencies:
dodb:
git: ../dodb.cr/
pg:
github: will/crystal-pg
crystal: '>= 1.12.1'
license: ISC

2
spec/spec_helper.cr Normal file
View File

@ -0,0 +1,2 @@
require "spec"
require "../src/test-db"

9
spec/test-db_spec.cr Normal file
View File

@ -0,0 +1,9 @@
require "./spec_helper"
describe Test::Db do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end

25
src/psql-query-one.cr Normal file
View File

@ -0,0 +1,25 @@
require "db"
require "pg"
nb_run = ARGV[1].to_i rescue 1000
DB.open(ENV["DATABASE_URL"]) do |db|
i = 0
while i < nb_run
i += 1
t1 = Time.monotonic
data = db.query_one(ARGV[0], &.read)
t2 = Time.monotonic
elapsed_time = t2 - t1
pp! elapsed_time, data
end
end
# PSQL_CONNECTION_STRING = "postgres://user:pass@host:port/db_name?option1=a&option2=b"
#PSQL_CONNECTION_STRING = "postgres://coucou:LOOKATMYPASS@host:port/db_name"
#DB.open(PSQL_CONNECTION_STRING) do |db|
# # TODO
# elapsed_time = Time.measure do
# end
#end