Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scientifichackers/sql2code

Convert SQL to import-able code!
https://github.com/scientifichackers/sql2code

Last synced: 3 days ago
JSON representation

Convert SQL to import-able code!

Awesome Lists containing this project

README

        

# SQL 2 code

This project lets you write functions in SQL and import them in code.

Currently, it only supports dart.

```console
$ pip install sql2code
```

```sql
-- queries1.sql
listMessages(sender, limit, offset) {
SELECT *
FROM message
WHERE sender = $sender
ORDER BY sentAt
LIMIT $limit OFFSET $offset;
}
```

```console
$ sql2dart quries.sql queries.dart
```

```dart
// queries.dart
import 'package:sqflite/sqflite.dart';

Future>> 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],
);
});
}
```