DEV Community

Cover image for Making SQLite Easy with Codesphere!
Simon Pfeiffer for Codesphere Inc.

Posted on

5 1

Making SQLite Easy with Codesphere!

Working with SQLite just got a whole lot easier! Codesphere is happy to announce a new UI for creating and managing your SQLite databases!

Let's talk about how!


Setting Up Your Database

To create a new database file, navigate to the infrastructure tab in Codesphere's IDE and select SQLite.

Alt Text

You can then create and name a new database, and Codesphere will automatically create the DB file for your database:

Alt Text

We'll name our database user_info, and then click on it to enter the SQL Query Editor Tab

Alt Text

The Query Editor Tab will allow you to easily run SQL queries to make ad-hoc insertions and deletions, view data, and set up and organize tables.


Making Queries in the Codesphere UI

To start off, we can create a table with:

CREATE TABLE user_info (
 name varchar(255),
 age int,
 active boolean
)
Enter fullscreen mode Exit fullscreen mode

Alt Text

To populate that table with a row:

INSERT INTO user_info
VALUES ('John Doe', 25, true);
Enter fullscreen mode Exit fullscreen mode

Alt Text

And then we can grab those values with:

SELECT * FROM user_info


Making Queries from NodeJS

You'll notice that the .db file is in your file tree.

In NodeJS, you can access this database by installing sqlite3

npm install sqlite3

And running the following code

const sqlite3 = require('sqlite3').verbose()
let db = new sqlite3.Database('./users.db')
let sql = `SELECT * FROM user_info`
db.all(sql, [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((row) => {
console.log(row)
})
})
db.close()
view raw index.js hosted with ❤ by GitHub

So what project are you going to use SQLite for?
Let us know down below!

Happy Coding from your friends at Codesphere.

API Trace View

Struggling with slow API calls? 🕒

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay