Working with your database is simple. Use our chainable commands to find, add, update, and remove data.
Read Data (Select)
Get Everything
Fetch all rows from a table.
const { data , error , count } = await corebase
. from ( 'posts' )
. select ( '*' );
Get Specific Fields
Fetch only the columns you need.
const { data } = await corebase
. from ( 'users' )
. select ( 'id, name, email' );
Filter Results
Find specific data (like WHERE in SQL).
const { data } = await corebase
. from ( 'posts' )
. select ( '*' )
. eq ( 'status' , 'published' )
. match ({ author_id: 'user_123' , category: 'tech' });
Sort and Limit
Order your results and pick how many to show.
const { data , count } = await corebase
. from ( 'posts' )
. select ( '*' )
. order ( 'created_at' , { ascending: false }) // Newest first
. limit ( 10 ) // Only 10
. page ( 1 ); // Page 1
Get One Record
Fetch a single specific row.
const { data : user , error } = await corebase
. from ( 'users' )
. select ( '*' )
. eq ( 'id' , 1 )
. single ();
Add Data (Insert)
Add new rows to your table.
Add one row
Add multiple rows
const { data , error } = await corebase
. from ( 'posts' )
. insert ({
title: 'My New Post' ,
content: 'Hello World' ,
user_id: 'user_123'
});
Update Data
Change existing data.
const { data , error } = await corebase
. from ( 'posts' )
. update ({ status: 'archived' }) // Change this
. eq ( 'status' , 'draft' ) // For these rows
. match ({ user_id: 'user_123' });
Remove Data (Delete)
Remove rows from your table.
const { data , error } = await corebase
. from ( 'posts' )
. delete ()
. eq ( 'id' , 123 );
If you use TypeScript, you can define your data types to get autocomplete and error checking. // 1. Define your data shape
interface Post {
id : number ;
title : string ;
content : string ;
}
// 2. Pass it to the .from() method
const { data } = await corebase . from < Post >( 'posts' ). select ( '*' );
// data is now typed as Post[] | null
Managing Tables (Schema)
Everything above works on row data. To define the shape of your tables, use corebase.db instead.
Create a Table
const { data , error } = await corebase . db . createTable ({
table: 'posts' ,
columns: [
{ name: 'id' , type: 'text' , primary: true },
{ name: 'title' , type: 'text' , notNull: true },
{
name: 'author_id' ,
type: 'text' ,
references: { table: 'users' , column: 'id' , onDelete: 'cascade' },
},
],
indexes: [{ columns: [ 'author_id' ] }],
});
rls (row-level security expressions) can be attached to a table today, but the
gateway does not enforce them yet — treat it as reserved for a future release, not a
working access control mechanism.
List & Inspect Tables
const { data : tables } = await corebase . db . listTables ();
const { data : schema } = await corebase . db . getTable ( 'posts' );
Add, Rename, or Remove a Column
await corebase . db . addColumn ( 'posts' , { name: 'published' , type: 'boolean' });
await corebase . db . renameColumn ( 'posts' , 'published' , { name: 'is_published' });
await corebase . db . deleteColumn ( 'posts' , 'is_published' );
Add a Foreign Key
await corebase . db . addForeignKey ( 'posts' , {
column: 'author_id' ,
references: { table: 'users' , column: 'id' , onDelete: 'cascade' },
});
Adding a foreign key rebuilds the table under the hood — batch schema changes
together when you can, rather than making them one at a time.