This project lets you write functions in SQL and import them in code.
Currently, it only supports dart.
$ pip install sql2code
-- queries1.sql
listMessages(sender, limit, offset) {
SELECT *
FROM message
WHERE sender = $sender
ORDER BY sentAt
LIMIT $limit OFFSET $offset;
}
$ sql2dart quries.sql queries.dart
// queries.dart
import 'package:sqflite/sqflite.dart';
Future<List<Map<String, dynamic>>> listMessages(
Database db,
sender,
limit,
offset,
) async {
return await db.transaction((txn) async {
return await txn.rawQuery(
"""SELECT * FROM message WHERE sender = ? ORDER BY sentAt LIMIT ? OFFSET ? """,
[sender, limit, offset],
);
});
}