From 9bb808ae7fc5b34525c694366d5709173bcaab48 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Fri, 8 Nov 2024 20:37:17 -0300 Subject: [PATCH] kjkjsakjdsaha9dusadijsalksadsd --- LICENSE | 21 +++++++++++++++ README.md | 27 ++++++++++++++++++++ shard.lock | 10 ++++++++ shard.yml | 19 ++++++++++++++ spec/crystal-jsonb-test_spec.cr | 9 +++++++ spec/spec_helper.cr | 2 ++ src/crystal-jsonb-test.cr | 30 ++++++++++++++++++++++ src/real.cr | 22 ++++++++++++++++ src/xd.cr | 45 +++++++++++++++++++++++++++++++++ 9 files changed, 185 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 shard.lock create mode 100644 shard.yml create mode 100644 spec/crystal-jsonb-test_spec.cr create mode 100644 spec/spec_helper.cr create mode 100644 src/crystal-jsonb-test.cr create mode 100644 src/real.cr create mode 100644 src/xd.cr diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..86b560e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Fijxu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e3c946 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# crystal-jsonb-test + +TODO: Write a description here + +## Installation + +TODO: Write installation instructions here + +## Usage + +TODO: Write usage instructions here + +## Development + +TODO: Write development instructions here + +## Contributing + +1. Fork it () +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create a new Pull Request + +## Contributors + +- [Fijxu](https://github.com/your-github-user) - creator and maintainer diff --git a/shard.lock b/shard.lock new file mode 100644 index 0000000..7c77669 --- /dev/null +++ b/shard.lock @@ -0,0 +1,10 @@ +version: 2.0 +shards: + db: + git: https://github.com/crystal-lang/crystal-db.git + version: 0.13.1 + + pg: + git: https://github.com/will/crystal-pg.git + version: 0.29.0 + diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..a59ea3d --- /dev/null +++ b/shard.yml @@ -0,0 +1,19 @@ +name: crystal-jsonb-test +version: 0.1.0 + +authors: + - Fijxu + +targets: + crystal-jsonb-test: + main: src/crystal-jsonb-test.cr + +dependencies: + db: + github: crystal-lang/crystal-db + pg: + github: will/crystal-pg + +crystal: '>= 1.13.3' + +license: MIT diff --git a/spec/crystal-jsonb-test_spec.cr b/spec/crystal-jsonb-test_spec.cr new file mode 100644 index 0000000..f70ceae --- /dev/null +++ b/spec/crystal-jsonb-test_spec.cr @@ -0,0 +1,9 @@ +require "./spec_helper" + +describe Crystal::Jsonb::Test do + # TODO: Write tests + + it "works" do + false.should eq(true) + end +end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr new file mode 100644 index 0000000..e984d16 --- /dev/null +++ b/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/crystal-jsonb-test" diff --git a/src/crystal-jsonb-test.cr b/src/crystal-jsonb-test.cr new file mode 100644 index 0000000..75957d4 --- /dev/null +++ b/src/crystal-jsonb-test.cr @@ -0,0 +1,30 @@ +require "db" +require "pg" + +require "json" + +PG_DB = DB.open "postgres://postgres:postgres@127.0.0.1:5432/postgres" + +PG_DB.exec("CREATE TABLE IF NOT EXISTS test4 (id SERIAL PRIMARY KEY, data JSONB)") + +json = JSON.build do |json| + json.object do + json.field "xd", "xd" + end +end + +insert = <<-SQL +INSERT INTO test4 (data) VALUES ($1) +SQL + +PG_DB.exec(insert, json) +result = PG_DB.query_one("SELECT data FROM test4 WHERE id = 1", as: JSON::Any) +puts result["xd"] + +# update = <<-SQL +# UPDATE test4 +# SET data = array_append(data, $1) +# WHERE id = $2 +# SQL + +# PG_DB.exec(update, json, 1) \ No newline at end of file diff --git a/src/real.cr b/src/real.cr new file mode 100644 index 0000000..9ac46e9 --- /dev/null +++ b/src/real.cr @@ -0,0 +1,22 @@ +require "db" +require "pg" + +require "json" + +PG_DB = DB.open "postgres://postgres:postgres@127.0.0.1:5432/postgres" + +PG_DB.exec("CREATE TABLE IF NOT EXISTS test2 (id SERIAL PRIMARY KEY, data JSONB)") + +# json = %({ "xd": "xd" }) + +json = JSON.build do |json| + json.object do + json.field "xd", "xd" + end +end + +PG_DB.exec("INSERT INTO test2 (data) VALUES ($1)", json) + +result = PG_DB.query_one("SELECT data FROM test2 WHERE id = 1", as: JSON::Any) + +puts result["xd"] diff --git a/src/xd.cr b/src/xd.cr new file mode 100644 index 0000000..eda3f7b --- /dev/null +++ b/src/xd.cr @@ -0,0 +1,45 @@ +require "db" +require "pg" + +require "json" + +PG_DB = DB.open "postgres://postgres:postgres@127.0.0.1:5432/postgres" + +PG_DB.exec("CREATE TABLE IF NOT EXISTS test (id TEXT PRIMARY KEY, data _JSONB)") + + +json : String = %({ "name": "John", "age": 30, "city": "New York" }) + + + +# # json = JSON.build do |json| +# # json.object do +# # json.field "name", "John" +# # json.field "age", 30 +# # json.field "city", "New York" +# # end +# # end + +# PG_DB.exec("INSERT INTO test (id, data) VALUES ('fijxu', '#{json}')") + +# # PG_DB.exec("INSERT INTO test (id, data) VALUES ('fijxu', '#{json}')") + +# # result = PG_DB.query_one("SELECT data FROM test WHERE id = 1", as: JSON::Any) + +# # puts result["name"] # => "John" + +# request = <<-SQL +# UPDATE test +# SET data = array_append(data, $1) +# WHERE id = $2 +# SQL + +# # PG_DB.exec(request, json, "fijxu") + +# result = PG_DB.query_one("SELECT data FROM test WHERE id = $1", "fijxu", as: JSON::Any) + +# # puts result["name"] # => "John" + + +# pp result +