简体   繁体   中英

Dart mysql insert placeholders in map

1) Is there some chance to insert huge placeholder via Map?

Example:

Map<String, dynamic> job = {
    'status': 'test',
    'id_sitemap': 2500,
    'id_job': 12,
    'contact_uuid': 'nejakeuuid',
    'id_source': 250,
     ...
     more 90 cols
  };

  await connection.query('INSERT INTO jobs', job);

2) How can I use mysql transaction? I'm using package mysql1 for Dart.

maybe its a little to late, but for others finding this post. You can do it in this way, not perfect, but little more flexible:

final sql = '''
  INSERT INTO jobs 
    (${job.keys.toList().join(',')}) 
  VALUES 
    (${List.filled(job.keys.length, '?').join(',')})   
''';
await connection.query(sql, job.values.toList());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM