Giter Site home page Giter Site logo

lecture01's Introduction

Info340b โ€” Lecture 01

Overview

The examples included in this repo introduce the basic concepts of reading and writing to a SQLite3 database before combining these concepts into a simple screen scraper that grabs posts from the Vertabelo bog and loads into our database.

Setup

Prior to running the examples, you will need to run the included script to create tables and import external Go modules.

go get github.com/mattn/go-sqlite3
go get github.com/PuerkitoBio/goquery
sqlite3 blog.db < create.sql

Alternatively, you can create the tables from within the SQLite3 shell using .open to load/create the database file and .read to execute the commands in the .sql file.

A similarly named drop.sql is also included to remove the tables from the database, though you might find it just as easy to delete the file itself and recreate.

Running Examples

Go examples can easily be run from the command line or through your IDE. From the command line, we use go run select.go to build and run the program (in this case our select.go example).

Since Go is a compiled language, it's also likely that we'll want to build in one step so that we can run the program natively. If a program excepts command line arguments, this is going to be the best strategy for testing (and you may find it easier to do from the terminal). Here's an example using insert.go, which inserts a row into the database based on our commandline arguments (careful ... we don't have any error checking):

go build insert.go
./insert author title 2016-04-03 http://test.com "summary text"

The ./ syntax is specific to *nix. Go on Windows compiles the program into the .exe format natively such that you can just run insert followed by the proper arguments.

lecture01's People

Watchers

James Cloos avatar  avatar

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.