Skip to content

Instantly share code, notes, and snippets.

@RX14

RX14/sql.cr Secret

Created February 17, 2017 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RX14/70cb68c564acd6c42920530cd3bfc69d to your computer and use it in GitHub Desktop.
Save RX14/70cb68c564acd6c42920530cd3bfc69d to your computer and use it in GitHub Desktop.
def insert_into(table, data)
columns = data.keys.join(", ")
placeholders = (1..data.size).map { |i| "$#{i}" }.join(", ")
sql = "INSERT INTO #{table} (#{columns}) VALUES (#{placeholders})"
db.exec(sql, *data.values)
end
insert_into "users", {
id: id,
signup_time: Time.now,
username: user.username,
email: user.email,
password_bcrypt: bcrypt(user.password),
avatar_id: user.avatar_id,
usertitle: user.usertitle,
signature_bbcode: user.signature_bbcode,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment