Git Product home page Git Product logo

hello-sqlite3's Introduction

getting started with sqlite

$ sudo apt install sqlite3

There are many databases out there. We'll focus on the simplest one first called sqlite. For our projects we use PostgreSQL, but as an introduction to SQL sqlite is a good start.

To create a database for our bookHunt app,

sqlite3 book_hunt.db

Now we'd be inside sqlite and not our shell.

sqlite>

CREATE TABLE novels
(
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT,
  createdAt TEXT,
  updatedAt TEXT
);

this is an example of DDL - data definition language

to view tables

.tables

to see the schema of a table

.schema tablename

Create

inserting an entry

INSERT INTO novels
(name, createdAt, updatedAt)
VALUES
("Harry Potter", "2022-12-26T06:37:45.977Z", "2022-12-26T06:37:45.977Z");

INSERT INTO novels
(name, createdAt, updatedAt)
VALUES
("IT", "2022-12-26T06:39:08.243Z", "2022-12-26T06:39:08.243Z"),
("Alice in wonderland", "2022-12-26T06:39:33.481Z", "2022-12-26T06:39:33.481Z");

Read

sqlite> select id, name from novels;
sqlite> select * from novels;
1|Harry Potter|2022-12-26T06:37:45.977Z|2022-12-26T06:37:45.977Z
2|IT|2022-12-26T06:39:08.243Z|2022-12-26T06:39:08.243Z
3|Alice in wonderland|2022-12-26T06:39:33.481Z|2022-12-26T06:39:33.481Z
sqlite> select * from novels where id < 2;
1|Harry Potter|2022-12-26T06:37:45.977Z|2022-12-26T06:37:45.977Z
sqlite> select * from novels where id =2;
2|IT|2022-12-26T06:39:08.243Z|2022-12-26T06:39:08.243Z

Update

sqlite> update novels set name="Harry Potter 2" where id =1;

Delete

sqlite> delete from novels where id =1;
sqlite> select * from novels;
2|IT|2022-12-26T06:39:08.243Z|2022-12-26T06:39:08.243Z
3|Alice in wonderland|2022-12-26T06:39:33.481Z|2022-12-26T06:39:33.481Z

resources

hello-sqlite3's People

Contributors

ashish-mw avatar

Watchers

 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.