Discuss or ask a question
Creating tables
Think about the tables required. I'd say two tables are required:
  • Girlfriend
  • Notes
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:
  1. You need to mark your entity classes with @Entity facet. You will also generally want to mark an Entity with @Js and @Serializable if you also want to share them with your client(js) code also written in fantom
  2. If the table name is different from your class name use the @Table{name="table_name"} facet, if the column name is different from your field name use @Column{name="table_name"} facet
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