|
Creating tables
Think about the tables required. I'd say two tables are required:
Let's create the two tables. Fire your mysql client and create the two tables like this:
CREATE TABLE girlfriend ( id int NOT NULL AUTO_INCREMENT, name varchar(30) DEFAULT NULL, PRIMARY KEY (`id`) ); CREATE TABLE gfnote ( id int(11) NOT NULL AUTO_INCREMENT, gfid int(11) DEFAULT NULL, text varchar(30) DEFAULT NULL, PRIMARY KEY (`id`) );
Creating Model Objects
Create the following two classes to represent the rows in two tables correspondingly
fan/GirlFriend.fan : using fanbatis
@Entity
class GirlFriend{
@Primary
@Autogen
Int? id
Str? name
DateTime? lastUpdated
}
fan/Note.fan : using fanbatis
@Entity
@Table{name="gfnote"}
class Note{
@Primary
@Autogen
Int? id
Int? gfId
Str? text
}
Quick things to note:
Quick fanbatis introduction (A.K.A how to query)
Once you have the model classes, you can do crud like this..
Fetch one GirlFriend row from db:
GirlFriend gf := Db.one(GirlFriend{it.id = id})
Fetch a list of all GirlFriend rows from db:
GirlFriend[] gfs := Db.list(GirlFriend{})
Create a GirlFriend row:
Db.create(GirlFriend{it.name = name})
Save a GirlFriend row:
GirlFriend gf := Db.one(GirlFriend{it.id = id})
gf.name = "new name"
Db.save(gf)
For more information on fanbatis look here
Now that we have our model classes ready, and know how to query, we can Start writing the ui code
|
