Skip to content
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 account related emails.

Already on GitHub? Sign in to your account

Select SQL query for the fluent-postgres-driver with bindings #214

Open
nikitakuzmin2017 opened this issue Jun 5, 2023 · 0 comments
Open

Comments

@nikitakuzmin2017
Copy link

nikitakuzmin2017 commented Jun 5, 2023

Hello everyone!
I do not understand how to put bindings properly in SQL query.
Always I just get 500 error.
I add them as 'PostgresData', then put after query SQL.
It looks like this:

// PostgreSQL
        var returnValue: [Song] = []
        
        guard let postgres = req.db as? PostgresDatabase else {
            throw Abort(.internalServerError)
        }
        
        let id = PostgresData(int32: 289) // add binding
        
        do {
            let results = try await postgres.query("SELECT songs FROM bangs WHERE songDuration = $1", [id]).get() // add binding here as an array, '$1' inside the array
            
            for result in results {
                returnValue.append(try result.sql().decode(model: Song.self))
            }
        } catch {
            throw Abort(.accepted) // error here!
        }
        return returnValue

Could you please help me, I am struggling with this for one week looking for any documentation.

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