Junior — Middle
Can you explain what SQLite is and what its main features are?
sobes.tech AI
Answer from AI
SQLite is an embedded relational database stored in a single file and does not require a separate server to operate. Key features of SQLite:
- Lightweight — small library size, easy to embed into applications.
- Serverless — the database works directly with the file, simplifying deployment.
- Support for standard SQL — allows the use of familiar queries.
- Transactions and reliability — supports ACID, ensuring data integrity.
- Cross-platform — runs on various operating systems.
SQLite is often used in mobile applications (e.g., iOS), desktop programs, and for local data storage where a complex client-server architecture is not required.
Example of creating a table and inserting data in SQLite (Swift):
import SQLite3
var db: OpaquePointer?
if sqlite3_open("mydb.sqlite", &db) == SQLITE_OK {
let createTableQuery = "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT);"
sqlite3_exec(db, createTableQuery, nil, nil, nil)
let insertQuery = "INSERT INTO users (name) VALUES ('Ivan');"
sqlite3_exec(db, insertQuery, nil, nil, nil)
sqlite3_close(db)
}