Coder Social home page Coder Social logo

roco-scientist / tsv_to_sql Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 47 KB

TSV to SQL for MySQL. Initial test project for learning Rust and how to convert python to rust. There are better implementations for converting TSV to SQL otherwise.

License: MIT License

Python 37.53% Rust 62.47%

tsv_to_sql's People

Contributors

roco-scientist avatar

tsv_to_sql's Issues

Implement edits suggested on Reddit

From Lvl999Noob on Reddit /r/leanrust

lib.rs is the library crate. The UI stuff (clap etc) should be in main.rs or one of its descendant modules.

Comment always have a space after the // | ///

e.g. -> /// Example Foo Bar โœ“ ///Example Foo Bar โŒ

I haven't looked at the code completely yet, so I'll update this answer later

Edit: 3. You can add another argument to force file type to tsv or csv. Some files might have tsv or csv somewhere in file name or the file contents might be entered through stdin (you can add that too actually)

Edit: 4. To split the file into header, first line etc, instead of comparing the index, you should have a mutable iterator and use next.

let mut header = String::new();
let mut first_row = String::new();
let mut body = Vec::new();
for (x, line) in text.lines().enumerate() {
    if x == 0 {
        header = line.to_string()
    };
    if x == 1 {
        first_row = line.to_string();
        body.push(line.to_string())
    };
    if x > 1 {
        body.push(line.to_string())
    };
}

You can have

let mut contents = text.lines();
let header = contents.next().unwrap().to_string();
let first_row = contents.next().unwrap().to_string();
let body = contents.map(|l| l.to_string()).collect::<Vec<String>>();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.