<commit_before>Quest = require '../../quest'

module.exports =
class ExampleQuest extends Quest
  makePeople: (peoples) ->
    peoples = peoples
      .map ({name, age}) -> "('#{name}', #{age})"
      .join ',\n'
    @sql file: 'people.sql', {people: peoples}

  getPeopleOlderThan: (minAge) ->
    try
      result = @sql """SELECT * FROM people
                       WHERE age > {{age}}""",
                    age: minAge

    catch e
      console.error "Failed to get people older than #{minAge}!"
      console.error e.message
      return []
    result.rows.map ({name}) -> name

  adventure: ->
    @makePeople [{name: 'Anthony', age: 20},
                 {name: 'Daniel', age: 21},
                 {name: 'Avram', age: 29}]

    console.log "People older than 20:".underline
    for i, person of @getPeopleOlderThan 20
      console.log "* #{person}".underline
    @transaction =>
      @sql "create temp table foo (x int);"
      @sql "insert into table foo VALUES ('on no');"

      # this will never happen
      @sql "create temp table bar as (select * from foo)"<commit_msg>Newline for readability.<commit_after>Quest = require '../../quest'

module.exports =
class ExampleQuest extends Quest
  makePeople: (peoples) ->
    peoples = peoples
      .map ({name, age}) -> "('#{name}', #{age})"
      .join ',\n'
    @sql file: 'people.sql', {people: peoples}

  getPeopleOlderThan: (minAge) ->
    try
      result = @sql """SELECT * FROM people
                       WHERE age > {{age}}""",
                    age: minAge

    catch e
      console.error "Failed to get people older than #{minAge}!"
      console.error e.message
      return []
    result.rows.map ({name}) -> name

  adventure: ->
    @makePeople [{name: 'Anthony', age: 20},
                 {name: 'Daniel', age: 21},
                 {name: 'Avram', age: 29}]

    console.log "People older than 20:".underline
    for i, person of @getPeopleOlderThan 20
      console.log "* #{person}".underline
    console.log()

    @transaction =>
      @sql "create temp table foo (x int);"
      @sql "insert into table foo VALUES ('on no');"

      # this will never happen
      @sql "create temp table bar as (select * from foo)"
{'fraction_non_alphanumeric': 0.1491862567811935, 'fraction_numerical': 0.009041591320072333, 'mean_word_length': 2.20260492040521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1536902', 'n_tokens_mistral': 684, 'n_tokens_neox': 644, 'n_words': 220}