Skip to content

jac3km4/sqlite4reds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlite4reds

Simple sqlite binding for redscript

usage

  • import the library
    import SQLite.*
  • load your database
    AttachDb("mydb");
  • create a table
    // you always need to refer to your db by name (mydb)
    let res = Execute("
      CREATE TABLE mydb.COMPANY(
        ID INT PRIMARY KEY     NOT NULL,
        NAME           TEXT    NOT NULL,
        AGE            INT     NOT NULL,
        ADDRESS        CHAR(50),
        SALARY         REAL
      )
    ");
    // Success(Array([]))
  • insert a row
    let res = Execute("
      INSERT INTO mydb.COMPANY (ID,NAME,AGE,ADDRESS,SALARY)
      VALUES (1, 'Paul', 32, 'California', 20000.00)
    ");
    // Success(Array([]))
  • query a table
    let res = Query("SELECT * FROM mydb.COMPANY where name = ?", ["Paul"]);
    if res.IsSuccess() {
      for row in (res as Success).GetRows() {
          let name = FromVariant<String>(row.columns[1]);
          let age = FromVariant<Int64>(row.columns[2]);
          // nullables can be checked using IsDefined
          let has_address = IsDefined(row.columns[3]);
          ...
        }
    }
  • handle errors
    // the Dump method logs the result which may be an error or a list of rows
    res.Dump();
    // each error has a message and an error code, and both can be inspected
    if !res.IsSuccess() {
      LogChannel(n"DEBUG", (res as Error).GetMessage());
    }

SQLite types

SQLite type Redscript input types (in queries) Redscript output type (in result columns)
INTEGER Int32, Int64, Uint32 Int64
REAL Float, Double Double
TEXT String String
BLOB Not supported Not supported

requirements

build

cargo build --release

About

Simple sqlite binding for redscript

Resources

License

Stars

Watchers

Forks

Packages

No packages published