| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This interface is the heart of jSQL and handles all database operations. There are 6 classes that implement this interface, depending on the query's type property. Query types are "CREATE", "UPDATE", "SELECT", "INSERT", "DROP", and "DELETE".
While all the methods of this interface are available in all of the classes that implement it, some of these methods only apply to certain types and if building a query, these methods should be called in logical order.
For example, in SQL, you would NOT say UPDATE USERS WHERE B = 3 SET C = 4. Likewise, in jSQL you wouldn't say jSQL.update(users).where('B').equals(3).set({C:4}) The correct SQL syntax is UPDATE USERS SET C = 4 WHERE B = 3 and likewise, the correct jSQL syntax is jSQL.update(users).set({C:4}).where('B').equals(3).
Used for "CREATE" queries to set a flag that will prevent overwriting this table if it already exists.
jSQL.createTable({myTable: [
{ name: "ID", type: "INT", args: [] },
{ name: "Name", type: "VARCHAR", args: [30] }
]}).ifNotExists().execute();
Used for "INSERT" queries to set a flag that will prevent an error from being thrown on a key violation.
jSQL.insertInto('myTable').values({ID:0, Name:'Bob'}).ignore().execute();
Used for ALL query types. This function executes the query, setting the result set, if any, and performing the operation on the tables.
jSQL.query('UPDATE Users SET Name = ?').execute(['Frank']);
Used for "SELECT" queries to return the first row in the result set.
var query =
jSQL.select('*')
.from('Users')
.where('Name')
.equals('Frank')
.execute();
var Frank = query.fetch('ASSOC');
Used for select queries to return the all rows in the result set.
var sql = 'SELECT `Name`, `Age` FROM `Users` WHERE `Age` > 32';
var query = jSQL.query(sql);
query.execute();
var oldPeople = query.fetchAll('ASSOC');
Used for "INSERT" queries to set the values to be inserted into the newly created row.
var q = jSQL.insertInto('Users').values({Name: "?", Age: "?"});
q.execute(['Susan', 37]);
Used for "UPDATE" queries to set the columns and values to be altered.
var q = jSQL.insertInto('Users').values({Name: "?", Age: "?"});
q.execute(['Susan', 37]);
Used for "DELETE", "SELECT", and "UPDATE" queries to refine the result set, or the set of results to be altered or deleted.
jSQL.deleteFrom('Users').where('Age').greaterThan(37).execute();
Used for "DELETE", "SELECT", and "UPDATE" queries to limit the result set, or the set of results to be altered or deleted.
jSQL.deleteFrom('Users').where('Age').greaterThan(37).limit(2, 7).execute();
Used for "DELETE", "SELECT", and "UPDATE" queries to sort the result set, or the set of results to be altered or deleted.
jSQL.deleteFrom('Users').where('Age').greaterThan(37).orderBy('Age').asc().limit(2, 7).execute();
Used for "DELETE", "SELECT", and "UPDATE" queries to sort the result set, or the set of results to be altered or deleted, in an ASCENDING order.
jSQL.deleteFrom('Users').where('Age').greaterThan(37).orderBy('Age').asc().limit(2, 7).execute();
Used for "DELETE", "SELECT", and "UPDATE" queries to sort the result set, or the set of results to be altered or deleted, in a DESCENDING order.
jSQL.deleteFrom('Users').where('Age').greaterThan(37).orderBy('Age').desc().limit(2, 7).execute();
Used for "DELETE", "SELECT", and "UPDATE" queries to ensure all rows in the result set are unique.
jSQL.select("*").distinct().from("myTable").execute();
Used for ""SELECT" queries to define the table from which to pull the results.
var allUsers = jSQL.select('*').from('Users').execute().fetchAll();
| Back | FazBrowse Home | New Git URL |