Coder Social home page Coder Social logo

crossdb-org / crossdb Goto Github PK

View Code? Open in Web Editor NEW
41.0 2.0 0.0 48 KB

The Fastest Embedded Database in the world✨

Home Page: https://crossdb.org

License: Apache License 2.0

C 100.00%
database embedded-database rdbms transaction in-memory-database in-service-software-upgrade embedded performance checkpoint storage

crossdb's Introduction

The Fastest Embedded Database in the world

CrossDB CLI

img

CrossDB Model

img

Learn CrossDB in 5 Minutes

🛶 Define Schema

typedef struct {
	uint32_t 			prefix;
	uint8_t 			mask;
	uint32_t			nexthop;
	uint8_t 			metric;
	char				intf[16];
	uint32_t			birth;
	uint32_t			flags;
} route_t;

#undef	CROSS_STRUCT_NAME
#define	CROSS_STRUCT_NAME	route_t
cross_field_t 	route_schema[] = {
	CROSS_FIELD (prefix,	UINT,	IPv4, 0),
	CROSS_FIELD (mask, 		UINT,	DFT,  0),
	CROSS_FIELD (nexthop,	UINT,	IPv4, 0),
	CROSS_FIELD (metric, 	UINT,	DFT,  0),
	CROSS_FIELD (intf,		CHAR,	DFT,  0),
	CROSS_FIELD (birth, 	UINT,	TS,   0),
	CROSS_FIELD (flags, 	UINT,	HEX,  0),
	CROSS_END (route_t)
};

⚙️ Create DB

#define CHECK(ret,str)		if (ret < 0) {	printf (str": %s\n", cross_errMsg(ret)); return -1; }

cross_db_h 		hDb;
cross_tbl_h 	hRtTbl;
cross_ret 		ret;
route_t 		route;	
cross_rowid 	count;

// Create database
ret = cross_dbCreate (&hDb, "db_data/example", 0);
CHECK (ret, "Failed to create db: example");

// Create table: route (Primary Key: prefix,mask)
ret = cross_dbTblCreate (hDb, &hRtTbl, "route", route_schema, "prefix,mask", 0);
CHECK (ret, "Failed to create table: route table");

// Create index on nexthop: idx_nexthop
ret = cross_dbIdxCreate (hRtTbl, "idx_nexthop", "nexthop", 0);
CHECK (ret, "Failed to create index: idx_nexthop");

⚜️ Insert Rows

#define IP4ADDR(a,b,c,d)	((a)<<24|(b)<<16|(c)<<8|(d))

// Insert route 192.168.1.0/24->192.168.1.254
route.prefix	= IP4ADDR(192,168,1,0);
route.mask		= 24;	
route.nexthop	= IP4ADDR(192,168,1,254);
route.metric	= 1;
route.flags		= 0;
strcpy (route.intf, "eth1");
route.birth		= time (NULL);
ret = cross_dbInsertRow (hRtTbl, &route, 0); 
CHECK (ret, "Failed to insert route 192.168.1.0/24");

🚀 Query Rows

#define IP4STR(ip)				ip>>24,(ip>>16)&0xff,(ip>>8)&0xff,ip&0xff

// Get single route 192.168.1.0/24 by Primary Key
route.prefix	= IP4ADDR(192,168,1,0);
route.mask		= 24;	
ret = cross_dbGetRowByPK (hRtTbl, &route, &route, 0); 
CHECK (ret, "Failed to get route 192.168.1.0/24 by Primary Key");
printf ("Get single route: %d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n",
		IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags);

// Get one row where nexthop=192.168.1.254
route.nexthop	= IP4ADDR(192,168,1,254);
ret = cross_dbGetOneRow (hRtTbl, "nexthop", &route, &route, 0);
CHECK (ret, "Failed to get one route where nexthop=192.168.1.254");
printf ("Get one route where nexthop=192.168.1.254: "
		"%d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n",
		IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags);

🔫 Update Rows

// Update single route 192.168.1.0/24 by Primary Key: set flags 0->1 metric 1->3
route.prefix	= IP4ADDR(192,168,1,0);
route.mask		= 24;	
route.metric	= 3;
route.flags		= 1;
ret = cross_dbUpdRowByPK (hRtTbl, &route, "flags,metric", &route, 0); 
CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key");

// Update routes where nexthop=192.168.1.254: set flags 0->3
route.nexthop	= IP4ADDR(192,168,1,254);
route.flags		= 3;
count = cross_dbUpdateRows (hRtTbl, "nexthop", &route, "flags", &route, 0);
printf ("Update %d routes where nexthop=10.1.2.254\n", count);

🎡 Cursor Query

// Use cursor to get routes where nexthop=192.168.1.254
cross_cursor_h hCursor;
route.nexthop	= IP4ADDR(192,168,1,254);
count = cross_dbQueryRows (hRtTbl, &hCursor, "nexthop", &route, 0);
printf ("Query %d routes where nexthop=192.168.1.254\n", count);
while (CROSS_OK == cross_cursorGetNextRow (hCursor, &route, 0)) {
	printf ("  route: %d.%d.%d.%d/%d->%d.%d.%d.%d intf: %s metric: %d flags: 0x%x\n",
			IP4STR(route.prefix), route.mask, IP4STR(route.nexthop), route.intf, route.metric, route.flags);
}
cross_cursorClose (hCursor, 0);

✂️ Delete Rows

// Delete single route 192.168.1.0/24 by Primary Key
route.prefix	= IP4ADDR(192,168,1,0);
route.mask		= 24;	
ret = cross_dbDelRowByPK (hRtTbl, &route, 0); 
CHECK (ret, "Failed to delete route 192.168.1.0/24 by Primary Key");

// Delete routes where nexthop=192.168.1.254
route.nexthop	= IP4ADDR(192,168,1,254);
count = cross_dbDeleteRows (hRtTbl, "nexthop", &route, 0);
printf ("Delete %d routes where nexthop=192.168.1.254\n", count);

🌄 Transaction

ret = cross_dbTransBegin (hDb, 0);
CHECK (ret, "Failed to begin transaction");
// Update single route 192.168.1.0/24 by Primary Key: set flags 0->5
route.prefix	= IP4ADDR(192,168,1,0);
route.mask		= 24;	
route.flags		= 5;
ret = cross_dbUpdRowByPK (hRtTbl, &route, "flags", &route, 0); 
CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key");
ret = cross_dbTransCommit (hDb, 0);
CHECK (ret, "Failed to commit transaction");

Want to Lean More?

https://crossdb.org

crossdb's People

Contributors

crossdbdev avatar jcwangxp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

crossdb's Issues

Price estimate?

I see your recent web-page:
https://crossdb.org/products/price/

Q1. If I have an app, if computer have 64-cores. so will process be limited to 1 core?
Is there a demo, where you can show, for example, if computer have 8 cores, all cores will be used to process data?

Q2. How does multiple EXEs (multiple apps) access 1 database? What price will that be? US$100 x 2 ... ?
How is this cross-db licensed, is it licensed per app?,
Can you explain?

Example.
App1 open database.
App2 opens database.
App1 writes to database.
App2... how does it get latest data?

Q3. How does license work?
If I buy bronze, what duration of support or updates?
2 years?, life-time, 1 year?

Q4. Is there price beyond diamond, if obtain sources?
How does it work? Is it licensed per user or per app, or some DB processing restriction... ?

The future of the CrossDB.

As a new non-open-source database product, why impose restrictions and charge for it? I suggest not charging because once you have a large user base and community, your traffic will increase, and the money will naturally come in without relying on selling the product itself. What do you think? For example, I'm a new user, and I came across CrossDB on Google, but when I found out there are limitations and charges, I instantly lost interest in using it.

Source Access?

hi,
I would like source-code pre-access for this.

Can you make this commercial open-source?

Hint: create an account at https://opencollective.com/ and make this available for donations.

Can you indicate what price tier you want for preview source-code access?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.