Skip to content

scientifichackers/sql2code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL 2 code

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

About

Convert SQL to import-able code!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published