volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Invalid schema name quoting when eager loading. #583

Closed sno6 closed 5 years ago

sno6 commented 5 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v3.4.0

Database engine: Postgres

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE SCHEMA IF NOT EXISTS "go-backend";

CREATE TABLE IF NOT EXISTS "go-backend"."tokens" (
    id SERIAL PRIMARY KEY,
    uuid uuid NOT NULL,
    token text NOT NULL,
    user_id integer REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE TABLE IF NOT EXISTS "go-backend"."users" (
    id SERIAL PRIMARY KEY,
    uuid uuid NOT NULL,
    email text NOT NULL;
);

Issue

Running the following code

func (ts *TokenStore) Find(token string) (*model.Token, error) {
    return model.Tokens(
        qm.Where(fmt.Sprintf("%s = ?", model.TokenColumns.Token), token),
        qm.Load(model.TokenRels.User),
    ).One(context.Background(), ts.db.DB)
}

Produces the following error and SQL logs:

Error #01: model: failed to execute a one query for tokens: failed to eager load User: failed to eager load User: pq: syntax error at or near "-"

Logs:

SELECT * FROM "go-backend"."tokens" WHERE (token = $1) LIMIT 1;
[test-token]
SELECT * FROM go-backend.users WHERE ("id" IN ($1));
[{1 true}]

So it looks like when loading the user via the foreign key it hasn't quoted the schema name properly and tripped up.

Also, epic work on this project. A lot of effort and care has gone into it and it's been a pleasure to use.

aarondl commented 5 years ago

I think I got it. Test shows that it's working now. It's on the dev branch if you want to confirm it's working. Thanks for the kind words :) Re-open if there's any problems.