Skip to content

Instantly share code, notes, and snippets.

@thomasmarren
Created October 17, 2016 13:34
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 thomasmarren/7991c5e1f61007bd8356f52b5fb181ca to your computer and use it in GitHub Desktop.
Save thomasmarren/7991c5e1f61007bd8356f52b5fb181ca to your computer and use it in GitHub Desktop.
#Ruby:
def save
sql = "INSERT INTO users (name, age) VALUES (?, ?)"
DB[:conn].execute(sql, self.name, self.age)
@id = DB[:conn].execute("SELECT last_insert_rowid() FROM users")[0][0]
end
user = User.new(name: "Tom", age: 26)
user.save
#Active Record:
user = User.create(name: "Tom", age: 26)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment