Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 29 2019 01:15
  • Jan 29 2019 01:15
  • Jan 29 2019 01:14
  • Jan 29 2019 00:43
  • Jan 29 2019 00:43
  • Jan 28 2019 16:54

    will on master

    Remove nested it in numeric_spe… (compare)

  • Jan 28 2019 16:54
    will closed #158
  • Jan 28 2019 16:54
    will commented #158
  • Jan 28 2019 16:02
    bcardiff opened #158
  • Jan 28 2019 16:01

    bcardiff on fix-nested-it

    Remove nested it in numeric_spe… (compare)

  • Jan 28 2019 13:12
    bcardiff commented #70
  • Jan 28 2019 11:40
    girng commented #70
  • Jan 28 2019 11:36
    girng commented #70
  • Jan 28 2019 09:49
    ysbaddaden commented #70
  • Jan 28 2019 01:28
    dscottboggs commented #70
  • Jan 27 2019 23:00
    drum445 commented on c54fab4
  • Jan 26 2019 17:28
    dscottboggs commented #70
  • Jan 26 2019 07:27
    girng commented on 9a838e3
  • Jan 26 2019 07:15
    girng commented #70
  • Jan 26 2019 07:13
    girng commented #70
G. Gibson
@mistergibson
Seems like each db adapter class should keep its own list of types then
makes more sense I think
your thoughts?
Linas
@kaukas_gitlab
I also had this problem. Why don't the types come from the DB adapter?
Brian J. Cardiff
@bcardiff
Each driver has their own type. DB::Any serves as a common ground to allow some minimum guarantees. Since the connection uri might not be a literal, there is no way to know at compile time which driver is wanted if there are many included
If there is an actual issue, that something stop compiling because there were many drivers included, please share code.
Nathaniel Suchy
@nathanielsuchy
Is db.exec() or db.query() faster
I don't really need results, only confirmation the data inserted without errors
Nathaniel Suchy
@nathanielsuchy
inserting 1000s of keys at once so I just need to do a big insert and only worry about whether the transaction was successful or not
Nathaniel Suchy
@nathanielsuchy
BEGIN TRANSACTION;
INSERT INTO 'tablename' table VALUES ('data1', 'data2');
INSERT INTO 'tablename' table VALUES ('data3', 'data4');
...
COMMIT;
How would I create a transaction like this using Crystal's DB Library?
Would I just write a bunch of db.exec() statements starting with BEGIN and ending with COMMIT?
Nathaniel Suchy
@nathanielsuchy
also, not sure if it'd be relevent to me, I know you can do binded queries to prevent SQL Injection, is this necessary for parsing JSON Files (they don't include SQL Queries), what's the performance impact?
Brian J. Cardiff
@bcardiff
@nsuchy The performance support depends on the driver. Exec sounds better if you don’t want/need row kind results. I would suggest to use non prepared statements probably to run one time queries.
For transactions, there is already support for them http://crystal-lang.github.io/crystal-db/api/0.5.1/DB/Transaction.html the importan thing, if you want to do them manually is to checkout a connection from the pool.
Nathaniel Suchy
@nathanielsuchy
Nice
That makes things easier
I’ll be working with 1,000s of inserts
I heard transactions improve write performance
Nathaniel Suchy
@nathanielsuchy
@bcardiff Can you show me an example of running queries as a transaction?
Brian J. Cardiff
@bcardiff
@nsuchy the opening comment in crystal-lang/crystal-db#27 shows how to. Apologies for the lack of docs. I thought there was a bit more.
Nathaniel Suchy
@nathanielsuchy
@bcardiff Docs are kinda iffy :P
G. Gibson
@mistergibson
So, I can load more than ONE db driver at a time into my Crystal apps yes? I MUST be able to support multiple (and different) dbs in my app.
Brian J. Cardiff
@bcardiff
yes you can @mistergibson
G. Gibson
@mistergibson
SWEET
Ed
@drum445
Hi @mistergibson
G. Gibson
@mistergibson
Hey Ed
Thanks for seeking me out
@drum445 : I'm planning upon using a few db drivers to support 5 to 8 databases max. Does objectify track the source db of a given model's record?
G. Gibson
@mistergibson
@drum445 : ah, I see - silly question
G. Gibson
@mistergibson
@drum445 : how do I set a model property as table key and perhaps nillable true/false?
@drum445 : as well as declare default value?
Ed
@drum445
class Note
  include Objectify::Mappable
  property note_id : String
  property content : String? # This type is (String | Nil)
end
Include Objectify::Mappable in the class, to allow a field to be nillable add Crystal's ? syntax after the data type
G. Gibson
@mistergibson
cool
ok
thanks
Ed
@drum445
np sir
G. Gibson
@mistergibson
So, setting default would be done during table creation?
Ed
@drum445
Yep, I'd say it's better to be handled by your DB
G. Gibson
@mistergibson
@drum445 : have you ever used Sequel in Ruby?
Christian Kakesa
@fenicks
Hi guys, how can I set specifically the password in connection db ? The uri connection string have a '@' in password in my case ? Or how can I protect the '@' in password section from the uri string ?
Brian J. Cardiff
@bcardiff
@fenicks use %40 where the password has a @.
If there are other weird chards, you can use https://www.urlencoder.org/ to check how to encode them in a uri friendly manner
Christian Kakesa
@fenicks
@bcardiff Thank you, it works perfectly.
vsmilesv
@vsmilesv
Hello, a complete newbie here, trying to connect some crystal code to a PG database, but cannot figure how to resolve the 'Error: already initialized constant DB::TYPES'. I followed all the crystal docs instructions on the crystal-db usage and the relevant APIs but am not sure what I'm doing wrong... Any help greatly appreciated.... Thanks
# TODO: Write documentation for `test`
require "DB"
require "PG"

module test
  VERSION = "0.1.0"

  # TODO: Put your code here

  db = DB.open "postgres://localhost:5432/crystal_test"

  begin
    db.exec "create table contacts (name varchar(30), age int)"

  ensure

  db.close
  end

end
Jordano Moscoso
@PlayLights_twitter
That is weird, have you tried import in lowercase?
Also remove the line module since you are defining the program without module methods
vsmilesv
@vsmilesv

That is weird, have you tried import in lowercase?

Thanks for getting back to me - tried your recommendations but still getting the same error. I should have mentioned, I am using dockers for both, crystal and PG - not sure if this has any impact...?

vsmilesv
@vsmilesv
Ooops, sorry, my bad, your suggestion actually worked but I got a different error now
'''
Unhandled exception: (no message) (DB::ConnectionRefused)
from lib/pg/src/pg/connection.cr:16:9 in 'initialize'
from lib/pg/src/pg/connection.cr:7:5 in 'new'
from lib/pg/src/pg/driver.cr:3:5 in 'build_connection'
from lib/db/src/db/database.cr:57:9 in '->'
from ../../usr/share/crystal/src/primitives.cr:255:3 in 'build_resource'
from lib/db/src/db/pool.cr:45:34 in 'initialize'
from lib/db/src/db/pool.cr:38:5 in 'new:initial_pool_size:max_pool_size:max_idle_pool_size:checkout_timeout:retry_attempts:retry_delay'
from lib/db/src/db/database.cr:56:15 in 'initialize'
from lib/db/src/db/database.cr:49:5 in 'new'
from lib/db/src/db.cr:152:5 in 'build_database'
from lib/db/src/db.cr:148:5 in 'build_database'
from lib/db/src/db.cr:116:5 in 'open'
from nltest.cr:10:3 in 'crystal_main'
from ../../usr/share/crystal/src/crystal/main.cr:105:5 in 'main_user_code'
from ../../usr/share/crystal/src/crystal/main.cr:91:7 in 'main'
from ../../usr/share/crystal/src/crystal/main.cr:114:3 in 'main'
from
libc_start_main
from _start
from ???
'''
Jordano Moscoso
@PlayLights_twitter
Yea, looks like you are not sending the db credentials on the url