Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:47
    straight-shoota closed #12051
  • 13:47
    straight-shoota closed #12050
  • 12:17
    beta-ziliani edited #7318
  • May 15 08:43
    r00ster91 closed #7318
  • May 15 08:17
    r00ster91 closed #7690
  • May 14 17:01
    Blacksmoke16 labeled #11995
  • May 14 13:03
    webhive closed #12055
  • May 14 10:19
    straight-shoota milestoned #12051
  • May 14 10:00
    I3oris edited #12051
  • May 14 08:45
    oprypin review_requested #11977
  • May 13 23:29
    Blacksmoke16 unlabeled #12061
  • May 13 22:56
    Blacksmoke16 edited #12061
  • May 13 22:56
    Blacksmoke16 edited #12061
  • May 13 22:54
    Blacksmoke16 labeled #12061
  • May 13 22:54
    Blacksmoke16 labeled #12061
  • May 13 22:54
    Blacksmoke16 labeled #12061
  • May 13 22:54
    Blacksmoke16 opened #12061
  • May 13 20:14
    straight-shoota labeled #12060
  • May 13 20:14
    straight-shoota labeled #12060
  • May 13 20:14
    straight-shoota opened #12060
Rubi
@codenoid
hi, how to statically define this value ( {"key":"val","key":"val"} ) inside crystal variable
Serdar Dogruyol - Sedo セド
@sdogruyol
@codenoid
STATIC_VAR = {"key":"val","key":"val"}
Indra Gunawan
@coderbuzz
Morning...
Rubi
@codenoid
nope, wont work @sdogruyol
it's a json value, please,
Syntax error in src/toped.cr:8: expecting token '=>', not 'val'

STATIC_VAR = {"key":"val","key":"val"}
Serdar Dogruyol - Sedo セド
@sdogruyol
Hanyuan Li
@hanyuone
bmcginty Whoa, that's neat :)
Rubi
@codenoid
my static value is {"key":"val","key":"val"} not {"key" => "val","key" =>"val"}
Serdar Dogruyol - Sedo セド
@sdogruyol
the first is a NamedTuple the second is a Hash
Hanyuan Li
@hanyuone
@codenoid => is Crystal syntax for key-value pairs
Rubi
@codenoid
but its json value :(
Hanyuan Li
@hanyuone
Ohhhhh
Sorry, my mistake
Serdar Dogruyol - Sedo セド
@sdogruyol
@codenoid i still don't get your point
Hanyuan Li
@hanyuone
I don't think you can do that, You might have to wrap it around a toJSON thing
Serdar Dogruyol - Sedo セド
@sdogruyol
just use a String then
Ghost
@ghost~55586c4815522ed4b3e08557
@codenoid you want var = %({"your": "json"})
Rubi
@codenoid
why crystal didnt read first " and last " as a opening and closing string
@bew cool thanks @bew
Ghost
@ghost~55586c4815522ed4b3e08557
:smile:
Because %() %[] and %<> are other string separators
Dru Jensen
@drujensen
or you could escape all the inner quotes ”{\"key\": \"val\",\"key2\": \"val\”}” but that is some ugly code ;)
Rubi
@codenoid
^ agree
Gabriel Torrecillas Sartori
@G4BB3R
This message was deleted

I need help, very beginner here. I am using Crecto, look my Repo.cr

module Repo
  extend Crecto::Repo

  config do |conf|
    conf.adapter = Crecto::Adapters::Mysql
    conf.database = "revistinha"
    conf.hostname = "localhost"
    conf.username = "root"
    conf.password = ""
    conf.port = 5432
  end
end

Then when I do this, it prints "Trying to insert" and then freezes forever, don't print nothing neither print an error

c = Consumidor.new
c.nome = "Gabb"
c.sobrenome = "Esperanto"

puts "Trying to insert..."
changeset = Repo.insert(c)
puts changeset.errors

After a few minutes waiting it throws an huge exception:
https://pastebin.com/TetU7nxy

unreadable
@unreadable
To be honest, I find it easier to work directly with the stdlib than the orm
Serdar Dogruyol - Sedo セド
@sdogruyol
@fridgerator can definitely help with that @G4BB3R
Gabriel Torrecillas Sartori
@G4BB3R
@krypton97 can I see a snippet of inserting/querying with your method? :)
it's written by the author of crecto :D
would definitely help you
unreadable
@unreadable
This is for inserting
    begin # assert for unique fiels
      SQLITE.exec "INSERT INTO users VALUES (?, ?, ?, ?)", SecureRandom.uuid, username, email, password
    rescue
      message = "Field already taken"
      render "views/register.ecr"
    else
      env.redirect "/"
    end
I'll paste for querying too
  res = SQLITE.query_one?("SELECT id, username, email, password FROM users WHERE username = ?", username, as: {String, String, String, String})
  if !res || res.last != password
    message = "Invalid username or password"
    render "views/login.ecr"
  else
    user = to_json({"id", "username", "email", "password"}, res)
    env.session.string("user", user)
    env.redirect("/")
  end
This is it pretty much all.
Serdar Dogruyol - Sedo セド
@sdogruyol
@krypton97 I also prefer your way
SQL is simple enough :)
Gabriel Torrecillas Sartori
@G4BB3R
damn now I can't decide xD
I was trying crecto because it seems to be productive
but this is very simple too
unreadable
@unreadable
Working with databases is one of the reasons I decided not to use go
From IRC (bridge bot)
@FromIRC
<Papierkorb> @krypton97, sidenote, please don't write a users table like that for production purposes.
Gabriel Torrecillas Sartori
@G4BB3R
why?
unreadable
@unreadable
anyway, I'm working on an auth sample with kemal
ikr lol
Gabriel Torrecillas Sartori
@G4BB3R
I am using Kemal too :)
The else after rescue is when everything is fine, without exceptions?
From IRC (bridge bot)
@FromIRC
<Papierkorb> yes
Gabriel Torrecillas Sartori
@G4BB3R
Great. thanks people
From IRC (bridge bot)
@FromIRC