8000 How to use columns which may be NULL? · Issue #45 · jmoiron/modl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

How to use columns which may be NULL? #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you 8000 account related emails.

Already on GitHub? Sign in to your account

Open
fd0 opened this issue May 1, 2016 · 1 comment
Open

How to use columns which may be NULL? #45

fd0 opened this issue May 1, 2016 · 1 comment

Comments

@fd0
Copy link
fd0 commented May 1, 2016

Hi, thanks for writing this library!

I don't understand how I can create a column that may be NULL in the database. Take a struct like the following:

type Person struct {
   ID int64
   BossID sql.NullInt64
}

When a database is created by modl, the type of the column BossID (at least for sqlite3) is text. Why is that?

I have found the code mapping a column to the type here: https://github.com/jmoiron/modl/blob/master/dialect.go#L111-L112 It seems that it does test for the type name NullableInt64 instead of NullInt64. Is that intentional or a bug? I was unable to find any reference to the string NullableInt64, except in an early discussion on how to name the types within sql.Null*.

Creating a custom type works, but I don't think that this is the way it is supposed to be:

type NullableInt64 sql.NullInt64

Now a database column with the type integer is created.

Am I missing something?

@fd0
Copy link
Author
fd0 commented May 1, 2016

For gorp, which modl is a fork of, this was changed in go-gorp/gorp@30f5a47 go-gorp/gorp#121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0