import db.sqlite

struct Parent {
	id    int    @[primary; sql: serial]
	name  string
	child Child  @[fkey: 'parent_id']
}

struct Child {
mut:
	id        int    @[primary; sql: serial]
	parent_id int
	name      string
}

fn get_first_child() Child {
	return Child{
		name: 'Lisa'
	}
}

fn get_second_child() Child {
	return Child{
		name: 'Steve'
	}
}

fn main() {
	mut db := sqlite.connect(':memory:') or { panic(err) }

	sql db {
		create table Parent
		create table Child
	}!

	new_parent := Parent{
		name: 'test'
		child: get_second_child()
	}

	sql db {
		insert new_parent into Parent
	}!

	first_child := get_first_child()

	sql db {
		insert first_child into Child
	}!

	steve := sql db {
		select from Parent where child == get_second_child()
	}!

	dump(steve)
}
