Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #23

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 53 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,53 +24,62 @@ View the [features](https://surrealdb.com/features), the latest [releases](https

```js
// import as ES module or common JS
import {Surreal} from 'surrealdb.node';
const {Surreal} = require('surrealdb.node');
const { default: Surreal } = require('surrealdb.node');

const db = new Surreal();

// use in-memory database
await db.connect('memory');
// connect to database server
await db.connect('ws://127.0.0.1:8000');
// use rocksdb file
await db.connect(`rocksdb://${process.cwd()}/test.db`);

// Select a specific namespace / database
await db.use({ ns: "test", db: "test" });

// Create a new person with a random id
let created = await db.create("person", {
title: "Founder & CEO",
name: {
first: "Tobie",
last: "Morgan Hitchcock",
},
marketing: true,
identifier: Math.random().toString(36).substr(2, 10),
});

// Update a person record with a specific id
let updated = await db.merge("person:jaime", {
marketing: true
});

// Select all people records
let people = await db.select("person");

// Perform a custom advanced query
let groups = await db.query(
"SELECT marketing, count() FROM type::table($table) GROUP BY marketing",
{
table: "person",
},
);

// Delete all people upto but not including Jaime
let deleted = await db.delete("person:..jaime");

// Delete all people
await db.delete("person");
async function main() {
try {

// Use any of these 3 connect methods to connect to the database
// 1.Connect to the database
await db.connect('http://127.0.0.1:8000/rpc');
// 2. Connect to database server
await db.connect('ws://127.0.0.1:8000');
// 3. Connect via rocksdb file
await db.connect(`rocksdb://${process.cwd()}/test.db`);

// Signin as a namespace, database, or root user
await db.signin({
username: 'root',
password: 'root',
});

// Select a specific namespace / database
await db.use({ namespace: 'test', database: 'test' });

// Create a new person with a random id
let created = await db.create('person', {
title: 'Founder & CEO',
name: {
first: 'Tobie',
last: 'Morgan Hitchcock',
},
marketing: true,
identifier: Math.random().toString(36).slice(2, 12),
});

// Update a person record with a specific id
let updated = await db.merge('person:jaime', {
marketing: true,
});

// Select all people records
let people = await db.select('person');

// Perform a custom advanced query
let groups = await db.query(
'SELECT marketing, count() FROM type::table($tb) GROUP BY marketing',
{
tb: 'person',
}
);
} catch (e) {
console.error('ERROR', e);
}
}

main();
```

# Supported targets
Expand Down
Loading