Skip to content

Latest commit

 

History

History
64 lines (41 loc) · 1010 Bytes

File metadata and controls

64 lines (41 loc) · 1010 Bytes

Database (SQLite3) in TechLang

TechLang supports SQLite3 databases for lightweight, file-based data storage and querying.

Connecting to a Database

Open or create a database file:

let db = sqlite_open("mydata.db")

Creating Tables

Create a new table:

db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INT)")

Inserting Data

Insert a record:

db.execute("INSERT INTO users (name, age) VALUES ('Alice', 30)")

Querying Data

Fetch data from a table:

let rows = db.query("SELECT * FROM users")
for row in rows {
    print(row["name"], row["age"])
}

Updating and Deleting Data

Update a record:

db.execute("UPDATE users SET age = 31 WHERE name = 'Alice'")

Delete a record:

db.execute("DELETE FROM users WHERE name = 'Alice'")

Closing the Database

Always close the database when done:

db.close()

See the Examples Index for more