We do a lot of work now using GO (golang.org), a newer programming language developed primarily at Google. GO is higher level than C but more nimble than Java, we like it a lot so far. However, we also do a lot of work with traditional SQL databases and there are some features I would like to see added to the GO database/sql package, such as ability to handle stored procedures with multiple result sets and more intuitive handling of NULL.
NULL is an important concept in programming, it means “nothing”, such as in systems programming when you try to address a non-existing memory location. In SQL databases NULL values are used frequently when you have to differentiate between non-existing and zero. For example, a zero degree outside temperature is a perfectly valid value, different from NULL which would indicate the user hasn’t entered an outside temperature yet.
In GO the variable type for time or date (time.Time) doesn’t accept NULL values so we wrote our own NullTime type, a variable that accepts either a valid date/time or NULL if the user hasn’t entered the date/time yet. Our code is essentially a copy of the NullTime type from the excellent lib/pg database driver, with added JSON input and output.
This whole NullTime effort had me thinking about Father Time a bit. I like to live in the moment but I’m also fascinated by the passing of time. We know 2 amazing Peruvian women who are in their 90s now and have fascinating stories of years gone by:
Mama Vicky
Patricia’s grandmother, affectionately known as Mama Vicky, is about 90 or 92 years old now, depending on who you ask. She lived most of her life in the small town of Accha and I don’t suppose in the 1920s civil register recordkeeping in small town Peru was very good. I believe her eldest son once told me Mama Vicky was born in 1925. Unfortunately her health hasn’t been the best for the past year or so but until Mama Vicky was well into her 80s, she’d never been admitted to a hospital. She gave birth to 12 kids – all at home – of whom only 8 lived.
Nowadays you can drive from Cusco to Accha in 3 to 4 hours and from the center of Cusco it takes nearly an hour just to get out of the “metropolitan” Cusco area. But it wasn’t always like that.
Recently Mama Vicky’s back started to bother her quite badly. We were at her house in the Ttio neighborhood of Cusco a few weeks ago when she told us that she believes her back pain stems from a horse accident years ago. Mama Vicky’s family were land owners before the Peruvian land reforms of the 1950s and 1960s. Her grandmother’s house was a colonial style house in downtown Cusco where the prestigious collegio Sta. Rosa is now located. In those days Cusco was many times smaller than it is now, all the surrounding areas which now make up the big city were nothing but farmland and villages. As a teenager Mama Vicky would watch every weekend as the men came from the countryside and each of the men would pick up or deliver hay for the horses, supplies for the land, and so on. Mama Vicky remembered every detail, from how many men would come to what they would each pick up or deliver, who worked the stables, the warehouse, etc.
When all was ready for the men who came to the house, Mama Vicky would get ready for her trip to Accha by horse. The trip from Cusco to Accha by horse would take 4 days, she told us exactly where they would stop every day to overnight, where they fed the horses, where the horses drank, etc. During one of the trips, in rainseason, there was an accident with one of the horses and Mama Vicky hurt her back, which is what she believes is causing her back pain today.
Mama Vicky hasn’t left the house in a few months, her health doesn’t allow much anymore. Last time she left the house we took her out to eat in Lucre – the best places to eat in Cusco aren’t in Cusco, they’re the quintas campestres in the towns around Cusco. Mama Vicky remembered who some of the houses belonged to 70 years ago, I think the horses stopped in Lucre on the way to Accha, I look at the town differently now.
Doña Laeti
Doña Laeti is one of Patricia’s best friends back in the US. In Cusquenian Spanish you rarely use Don or Doña, it shows a great deal of respect when you refer to someone as Don or Doña.
Doña Laeti was born in Trujillo, in the province of La Libertad in the North of Peru. She’s of mixed Peruvian and Chinese heritage, there is a lot of Asian influence in Peru. Doña Laeti is from a well to do family, pre World War II she would travel with her family from Peru to Hong Kong by steamship. She said the trip took about 4-6 weeks, with stops in places like San Francisco and Honolulu. They traveled well and she enjoyed the trip, I’m not sure but I believe her father was a diplomat.
When World War II broke out Doña Laeti and her family got caught up in the China – Japan conflict and she was interned along with some of her family in a Japanese concentration camp in China. Doña Laeti was only 19 and she worked in the camp as a nurse. Nowadays Doña Laeti and her sister laugh about the poor Chinese guy who died one night in the concentration camp because “grandma slept on top of him” – but you can still see the pain in their eyes all these years later.
Doña Laeti has letters from the Hong Kong government (before Hong Kong formally re-joined China) commending her for her efforts during the war. During the war Doña Laeti’s father got separated from the family – I believe he served in Italy – and when he found their house in China bombed to rubble after the war, her father started a new family only to be reunited years later.
In later years Doña Laeti traveled much of the world with her husband who was a diplomat and then became a writer, I believe he was a writer for the Washington Post, which in those days was known in intelligence circles as the newspaper of the US Army. Doña Laeti had 4 kids in 3 different countries, such is the life of a diplomat’s wife. I’m not sure that she’ll travel again but into her late 80s Doña Laeti would travel regularly from her home in the US to her family in Trujillo, where we’d typically go visit.
* * *
These tales seem so other worldly but they were merely a lifetime ago. It’s easy to get caught up in the hustle and bustle of everyday life, you get lulled into thinking the world has always been the way it is today. Doña Laeti and Mama Vicky know better.
But I wanted to make a point not about steamship voyages or treks on horseback but rather about people. The median age in Peru is quite young and the streets are full of young people. Whenever you see an occasional elderly person among the mob of young kids you can tell by the looks on the young kids’ faces:
They are convinced that old person has been old for their entire life.
In their youthful ignorance these young kids just know that people like Mama Vicky and Doña Laeti have been old ladies for all of their 90+ years in this world. Look at any young kid in the presence of an elderly person and tell me it ain’t so.
But if you listen to their stories, Mama Vicky still sounds like that teenage girl watching intently how the men came to pick up supplies for the land and the horses. Doña Laeti still sounds like the young kid who traveled the world by steamship. While they’re wondering how this dynamic young girl got stuck in the body of an old lady, young kids in the street walk by knowing that this will never happen to them, convinced they’ll be forever young.
* * *
* * *
Our golang NullTime type. We’re launching our first golang API server next month, I’ll let you know how it goes.
import (
“time”
“database/sql/driver”
)
// Type NullTime.
type NullTime struct {
Time time.Time
Valid bool // Valid is true if Time is not NULL
}
// JSON output.
// MarshalJSON implements the Marshaler interface.
func (nt NullTime) MarshalJSON() ([]byte, error) {
if nt.Valid {
return nt.Time.MarshalJSON()
}
return []byte(`null`), nil
}
// JSON input.
// UnmarshalJSON implements the Unmarshaler interface.
func (nt *NullTime) UnmarshalJSON(b []byte) error {
var myTime time.Time
err := myTime.UnmarshalJSON(b)
if err == nil {
nt.Time, nt.Valid = myTime, true
} else {
nt.Time, nt.Valid = *new(time.Time), false
}
return nil
}
// Download from SQL database.
// Scan implements the Scanner interface.
func (nt *NullTime) Scan(value interface{}) error {
nt.Time, nt.Valid = value.(time.Time)
return nil
}
// Insert in SQL database.
// A golang “zero date” is equivalent to dbase NULL.
// Value implements the driver Valuer interface.
func (nt NullTime) Value() (driver.Value, error) {
if !nt.Valid {
return nil, nil
}
if nt.Time.IsZero() {
return nil, nil
}
return nt.Time, nil
}