GoUDA : Go Unified Data Accessors

30
GoUDA : Go Unified Data Accessors Accessing Data in Go Benoît Larroque ECP SIO 04/12/2010

Transcript of GoUDA : Go Unified Data Accessors

GoUDA : Go Unified Data Accessors

Accessing Data in Go

Benoît Larroque ECP SIO 04/12/2010

Contents

The Go language

Programming using Data

GoUDA

The Go Language

Accessing Data in Go

Go Language

Go for Google

Public release : November 2009

A new release every two weeks

Vibrant mailing list

From its authors, Go is…

Simple : easy to code

Safe : no pointer arithmetic, garbage collected

Concurrent : built in concurrency

Fun : feels dynamic

Open source : permissive licence

Looks kind of like C

From sum.go

Programming using Data

Accessing Data in Go

Example

2 entity classes : Person & Car

A Person has many Carsid Name Age

1 Bob 12

2 Alice 23

3 Marc 18

id Owner_id Plate Model

1 2 AAA78 Scenic

2 3 BBB92 308

3 2 CCC99 Traban

Looking for :

Person with age = 18 or age >= 20 ordered by id desc

Their cars

1st method : Direct access

Direct file or structure access (i.e. no queries)

Files, CSV, XML perusing…

Hey, let’s hunt for our data !

Nota : Ruby is quite expressive !

Packages available in Go Standard Library

2nd method : Use bindings

Call a subsystem through a library

Use SQL (or a derivative)

Developers are in charge

Well, let’s ask our database…

Go bindings available for MySQL, PostgreSQL, MongoDB…

3rd method : Use an ORM

Developers ask for objects not data

Generally database agnostic

Still no compiler verification

I don’t even want to know where you got it !

Some research studies on improving ORMs

Until GoUDA none available in Go…

4th method : Native query language

Calling object stores right from the code

Need aware compilers

It’s a kind of magic !

Only found in LINQ

Results of research project Cω

Papers are hard to find…

Introducing GoUDA

Accessing Data in Go

Objectives

Meant for developers

Should be

Easy to use

Easy to read

Expressive

Self documenting

Backend agnostic

Architecture

Layered architecture

User Space

Models

Backend Adaptors

Ideal Query

Ideal Query

Actual Query

Actual Query : why ?

There are no class in Go Types are final

Can’t inject methods at runtime

Behind the scene

Persons is an instance of Model objectPersons

Behind the scene

Persons

A call to gouda.F initializes a Condition

Condition 0Age

Behind the scene

Persons

A call to Eq sets the type and value of the Condition

Condition 0Age == 18

Behind the scene

Persons

Same with the second Condition

Condition 0Age == 18

Condition 1Age >= 20

Behind the scene

Persons

A call to Or creates another Condition referencing the objects

Condition 0Age == 18

Condition 1Age >= 20

Condition 2Or

Behind the scene

Persons

A call to Where on the Model returns a ModelRelation instance

Condition 0Age == 18

Condition 1Age >= 20

Condition 2Or

ModelRelationCondition : cond 2

Behind the scene

Persons

All successive calls fill the object and then return a reference to it

Condition 0Age == 18

Condition 1Age >= 20

Condition 2Or

ModelRelationCondition : cond 2

Order : id DESC

Behind the scene

The last call to All uses the Model to fetch the requested objectsand returns an array

Condition 0Age == 18

Condition 1Age >= 20

Condition 2Or

ModelRelationCondition : cond 2

Order : id DESCPersons

Wrapping up

More than 2000 lines written

GoUDA can now “connects” to

MySQL : use a Go native binding

XML : self-contained in XMLAdaptor

Tested code (using gotest)

Has some support for associations

Open Source : MIT License

Conclusion

A nice and challenging project

Go really is a fun language to use

Might need more work before production

Go is also experimental !