-
Does GRDB have an API (more abstract than plain SQL string) for creating (temporary) SQL views? Given a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Hmmm... this is proving to be more difficult than I anticipated, and I'm stuck. I'm building my let sqlRequestLiteral: SQL = ...
dbPool.write { db in
let (sqlString, arguments) = try sqlRequestLiteral.build(db)
}
I would bet there's a SQLite API for accomplishing this sort of thing that GRDB does not expose. Help? 🙏 |
Beta Was this translation helpful? Give feedback.
-
CREATE VIEW usually runs inside migrations, and migrations should not use application record types. So people should not write: migrator.registerMigration("v45") { db in
// MOST PROBABLY WRONG: using a record type in a migration
try db.create(
view: "hero",
as: Player.filter(Column("score") > 1000))
} Instead they should write: migrator.registerMigration("v45") { db in
try db.create(view: "hero", as: """
SELECT * FROM player WHERE score > 1000
""")
} Which is not obviously better than: migrator.registerMigration("v45") { db in
try db.execute(sql: """
CREATE VIEW hero AS
SELECT * FROM player WHERE score > 1000
""")
} That's the reason why I never shipped CREATE VIEW apis.
This is correct. Thank you for shaking things up and bringing new ideas. |
Beta Was this translation helpful? Give feedback.
-
@groue I was able to implement a |
Beta Was this translation helpful? Give feedback.
Hello @mallman, there's no CREATE VIEW api yet, you're right :-)
SQLite does not accept arguments
?
in statements that modify the schema, as you noticed1.GRDB has internal apis that expand arguments into SQL literals. For example:
That's how the table creation apis can accept arguments: