Created
March 23, 2012 18:07
-
-
Save THUFIR/2173317 to your computer and use it in GitHub Desktop.
dwemthys msyql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thufir@dur:~/ruby/dwemthys$ | |
thufir@dur:~/ruby/dwemthys$ ruby connect.rb | |
connecting... | |
connected? | |
class Creature | |
life life | |
strength str | |
charisma char | |
weapon weapon | |
#<Creature:0x8bd5648> | |
[1]+ Stopped ruby connect.rb | |
thufir@dur:~/ruby/dwemthys$ | |
[1]+ Done ruby connect.rb | |
thufir@dur:~/ruby/dwemthys$ | |
thufir@dur:~/ruby/dwemthys$ cat connect.rb | |
require 'fileutils' | |
require 'active_record' | |
require_relative 'Creature' | |
require_relative 'Dragon' | |
puts "connecting..." | |
ActiveRecord::Base.establish_connection( | |
:adapter => "mysql", | |
:host => "localhost", | |
:username => "java", | |
:password => "password", | |
:database => "nntp" | |
) | |
puts "connected?" | |
c = Creature.new | |
c.life = "life" | |
c.strength = "str" | |
c.charisma = "char" | |
c.weapon = "weapon" | |
puts c | |
c.save | |
thufir@dur:~/ruby/dwemthys$ | |
thufir@dur:~/ruby/dwemthys$ cat Creature.rb | |
require 'active_record' | |
class Creature < ActiveRecord::Base | |
attr_accessor :life, :strength, :charisma, :weapon | |
def to_s () | |
print "class\t\t" | |
print self.class | |
print "\nlife\t\t" | |
print @life | |
print "\nstrength\t" | |
print @strength | |
print "\ncharisma\t" | |
print @charisma | |
print "\nweapon\t\t" | |
print @weapon | |
print "\n" | |
end | |
end | |
thufir@dur:~/ruby/dwemthys$ | |
thufir@dur:~/ruby/dwemthys$ mysql -u java -p | |
Enter password: | |
Welcome to the MySQL monitor. Commands end with ; or \g. | |
Your MySQL connection id is 238 | |
Server version: 5.1.58-1ubuntu1 (Ubuntu) | |
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. | |
This software comes with ABSOLUTELY NO WARRANTY. This is free software, | |
and you are welcome to modify and redistribute it under the GPL v2 license | |
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. | |
mysql> use nntp; | |
Reading table information for completion of table and column names | |
You can turn off this feature to get a quicker startup with -A | |
Database changed | |
mysql> select * from creatures; | |
+----+------+----------+----------+--------+ | |
| id | life | strength | charisma | weapon | | |
+----+------+----------+----------+--------+ | |
| 1 | NULL | NULL | NULL | NULL | | |
| 2 | NULL | NULL | NULL | NULL | | |
| 3 | NULL | NULL | NULL | NULL | | |
| 4 | NULL | NULL | NULL | NULL | | |
| 5 | NULL | NULL | NULL | NULL | | |
| 6 | NULL | NULL | NULL | NULL | | |
| 7 | NULL | NULL | NULL | NULL | | |
| 8 | NULL | NULL | NULL | NULL | | |
| 9 | NULL | NULL | NULL | NULL | | |
+----+------+----------+----------+--------+ | |
9 rows in set (0.00 sec) | |
mysql> quit; | |
Bye | |
thufir@dur:~/ruby/dwemthys$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment