Example #1
0
// CreateJourno creates a brand new journo in the database, given a name
func CreateJourno(tx *sql.Tx, name string) (*Journo, error) {
	base := baseRef(name)
	if base == "" {
		return nil, fmt.Errorf(`can't use journo name "%s"`, name)
	}

	// hit the DB to generate a unique ref
	ref, err := uniqRef(tx, base)
	if err != nil {
		return nil, err
	}

	//
	j := &Journo{}
	j.Status = "i"
	j.Ref = ref
	j.Prettyname = name
	j.Firstname, j.Lastname = splitName(name)
	j.FirstnameMetaphone = phonetics.EncodeMetaphone(j.Firstname)
	j.LastnameMetaphone = phonetics.EncodeMetaphone(j.Lastname)

	err = insertJourno(tx, j)
	if err != nil {
		return nil, err
	}
	// TODO: future: fill out journo_alias table, and also rel-author links etc to help resolution...
	return j, nil
}
Example #2
0
func createJourno(tx *sql.Tx, journo *arts.Author) (int, error) {
	ref, err := uniqRef(tx, baseRef(journo.Name))
	if err != nil {
		return 0, err
	}

	prettyName := journo.Name
	firstName, lastName := splitName(journo.Name)
	firstNameMetaphone := phonetics.EncodeMetaphone(firstName)
	lastNameMetaphone := phonetics.EncodeMetaphone(lastName)

	var journoID int
	err = tx.QueryRow(`INSERT INTO journo (id,ref,prettyname,firstname,lastname,firstname_metaphone,lastname_metaphone,created) VALUES (DEFAULT,$1,$2,$3,$4,$5,$6,NOW()) RETURNING id`,
		ref,
		prettyName,
		firstName,
		lastName,
		firstNameMetaphone,
		lastNameMetaphone).Scan(&journoID)
	if err != nil {
		return 0, err
	}

	// TODO: future: fill out journo_alias table, and also rel-author links etc to help resolution...

	return journoID, nil
}